TaskBatcher 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package TaskBatcher --version 2.0.1
                    
NuGet\Install-Package TaskBatcher -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TaskBatcher" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TaskBatcher" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="TaskBatcher" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TaskBatcher --version 2.0.1
                    
#r "nuget: TaskBatcher, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TaskBatcher@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TaskBatcher&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=TaskBatcher&version=2.0.1
                    
Install as a Cake Tool

TaskBatcher

This package collects incoming requests and processes them in batches. It is particularly useful in scenarios where multiple requests can be consolidated into a single database call, significantly reducing overhead and improving application scalability.

Usage/Examples

1) Define input that must be processed in batch:

public struct Input { public int V { get; init; } }

2) Define result:

public struct Result { public int V { get; init; } }

3) Add taskBatcher under some unique key:

builder.Services.AddTaskBatcher<Input, Result>(
	"myUniqueKey",
	(sp) =>
	{
		return async (Dictionary<string, Input> req) =>
		{
            //create scope:
			using var scope = sp.CreateScope();
            //get your services:
			var myService = scope.ServiceProvider.GetRequiredService<IMyService>();
			//process here bulk requests and return bulk result.
            //result id must match request id     
            Dictionary<string, Result> myResults = myService.Process(req);
            //return results:
			return myResults;
		};
	}
);

4) Inject the TaskBatcher into your service and pass the request:

public class MyService(
	[FromKeyedServices("myUniqueKey")] TaskBatcher<Input, Result> taskBatcher
) : IMyService {
    public async Task<Result> Example(Input req)
	{
		return await taskBatcher.Run(Guid.NewGuid().ToString(), new Input { V = 1 });
	}
}
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.9 472 11/19/2025
3.0.0 423 11/18/2025
2.1.2 422 11/18/2025
2.0.2 305 11/13/2025
2.0.1 175 10/11/2025