BatchSharp is a simple framework for batch application. This is inspired from Spring Batch.
BatchSharp can be installed using the Nuget package manager or the dotnet
CLI.
-
Package Manager
Install-Package BatchSharp
-
dotnet CLI
dotnet add package BatchSharp
-
Create the main class
using BatchSharp; using BatchSharp.Example; using BatchSharp.Example.Processor; using BatchSharp.Example.Reader; using BatchSharp.Example.Writer; using BatchSharp.Processor; using BatchSharp.Reader; using BatchSharp.Writer; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; var builder = Host.CreateDefaultBuilder(args) .ConfigureHostConfiguration(builder => { builder.AddBatchConfiguration(); }) .ConfigureServices((_, services) => { services.AddHostedService<BatchHostedService>() .AddScoped<IBatchApplication, ExampleBatchApplication>() .AddScoped<IReader<string>, ExampleReader>(); services.AddScoped<IProcessor<string, int>, ExampleProcessor>(); services.AddScoped<IWriter<int>, ExampleWriter>(); services.AddScoped<IStep, SimpleStep<string, int>>(); services.AddScoped<IStepState, StepState>(); }); var app = builder.Build(); await app.RunAsync();
-
Add the batch application endpoint
Configure batch application input and output type.
Add the class of application endpoint that extend
DefaultBatchApplication
class. First type parameter is input type, second type parameter is output type.IReader
is used to read input data.IProcessor
is used to process input data.IWriter
is used to write output data. These class are injected by DI container.public class ExampleBatchApplication : DefaultBatchApplication<string, int> { public ExampleBatchApplication( ILogger<ExampleBatchApplication> logger, IStep step) : base(logger, step) { } }