A lightweight batch-processing framework for .NET. Declarative step-based pipelines with chunking, skip policies, and restart-from-failure support.
$ dotnet add package NBatchA lightweight batch processing framework for .NET, inspired by Spring Batch.
📖 Full Documentation — guides, API reference, and examples.
NBatch gives you a declarative, step-based pipeline for ETL jobs, data migrations, and scheduled tasks. Wire up readers, processors, and writers — NBatch handles chunking, error skipping, progress tracking, and restart-from-failure.
| Package | Description |
|---|---|
NBatch | Core framework — interfaces, chunking, skip policies, CsvReader, DbReader/DbWriter, DI, hosted service |
NBatch.EntityFrameworkCore | EF Core job store for restart-from-failure (SQL Server, PostgreSQL, SQLite, MySQL/MariaDB) |
dotnet add package NBatch
dotnet add package NBatch.EntityFrameworkCore # only if you need persistent job tracking
var job = Job.CreateBuilder("ETL")
.AddStep("extract-transform", step => step
.ReadFrom(new CsvReader<Order>(...))
.WriteTo(new DbWriter<Order>(...))
.WithChunkSize(100))
.AddStep("notify", step => step
.Execute(() => SendEmail()))
.Build();
var job = Job.CreateBuilder("csv-import")
.UseJobStore(connStr, DatabaseProvider.SqlServer) // optional — enables restart-from-failure
.AddStep("import", step => step
.ReadFrom(new CsvReader<Product>("data.csv", mapFn)
.ProcessWith(p => new Product { Name = p.Name.ToUpper(), Price = p.Price })
.WriteTo(new DbWriter<Product>(dbContext))
.WithSkipPolicy(SkipPolicy.For<FormatException>(maxSkips: 5))
.WithChunkSize(100))
.AddStep("notify", step => step
.Execute(() => SendEmail()))
.Build();
await job.RunAsync();
builder.Services.AddNBatch(nbatch =>
{
nbatch.AddJob("csv-import", (sp, job) => job
.AddStep("import", step => step
.ReadFrom(new CsvReader<Product>("data.csv", mapFn))
.WriteTo(new DbWriter<Product>(sp.GetRequiredService<AppDbContext>()))
.WithChunkSize(100)))
.RunEvery(TimeSpan.FromHours(1));
});
AddNBatch(), RunOnce(), RunEvery() for background jobsSee the full documentation for guides, API reference, and examples:
CsvReader, DbReader, DbWriter, FlatFileItemWriterAddNBatch(), IJobRunner, RunOnce(), RunEvery()# Start the test database (SQL Server via Docker)
cd src && docker compose up -d
# Build & run the demo console app
dotnet build
dotnet run --project NBatch.ConsoleApp
# Run tests
dotnet test
git checkout -b my-featuregit commit -m "Add my feature"git push origin my-featureSee LICENSE for details.