MinimalWorker 2.0.2
See the version list below for details.
dotnet add package MinimalWorker --version 2.0.2
NuGet\Install-Package MinimalWorker -Version 2.0.2
<PackageReference Include="MinimalWorker" Version="2.0.2" />
<PackageVersion Include="MinimalWorker" Version="2.0.2" />
<PackageReference Include="MinimalWorker" />
paket add MinimalWorker --version 2.0.2
#r "nuget: MinimalWorker, 2.0.2"
#:package MinimalWorker@2.0.2
#addin nuget:?package=MinimalWorker&version=2.0.2
#tool nuget:?package=MinimalWorker&version=2.0.2
MinimalWorker

MinimalWorker is a lightweight .NET library that simplifies background worker registration in ASP.NET Core and .NET applications using the IHost interface. It offers three simple extension methods to map background tasks that run continuously or periodically, with support for dependency injection and cancellation tokens.
โจ Features
- ๐ Register background workers with a single method call
- โฑ Support for periodic background tasks
- ๐ Built-in support for
CancellationToken - ๐งช Works seamlessly with dependency injection (
IServiceProvider) - ๐งผ Minimal and clean API
๐ฆ Installation
Install from NuGet:
dotnet add package MinimalWorker
Or via the NuGet Package Manager:
Install-Package MinimalWorker
๐ Usage
Continuous Background Worker
app.RunBackgroundWorker(async (MyService service, CancellationToken token) =>
{
while (!token.IsCancellationRequested)
{
await service.DoWorkAsync();
await Task.Delay(1000, token);
}
});
Periodic Background Worker
app.RunPeriodicBackgroundWorker(TimeSpan.FromMinutes(5), async (MyService service, CancellationToken token) =>
{
await service.CleanupAsync();
});
Command run on notice (Cron) Background Worker
app.RunCronBackgroundWorker("0 0 * * *", async (CancellationToken ct, MyService service) =>
{
await service.SendDailyProgressReport();
});
All methods automatically resolve services from the DI container and inject the CancellationToken if it's a parameter.
Workers are automatically initialized and started when the application starts - no additional calls needed!
๐ง How It Works
RunBackgroundWorkerruns a background task once the application starts, and continues until shutdown.RunPeriodicBackgroundWorkerruns your task repeatedly at a fixed interval using PeriodicTimer.RunCronBackgroundWorkerruns your task repeatedly based on a CRON expression (UTC time), using NCrontab for timing.- Workers are initialized using source generators for AOT compatibility - no reflection at runtime!
- Workers automatically start when the application starts via
lifetime.ApplicationStarted.Register() - Services and parameters are resolved per execution using
CreateScope()to support scoped dependencies.
๐ AOT Compilation Support
MinimalWorker is fully compatible with .NET Native AOT compilation! The library uses source generators instead of reflection, making it perfect for AOT scenarios.
Publishing as AOT
To publish your application as a native AOT binary:
dotnet publish -c Release
Make sure your project file includes:
<PropertyGroup>
<PublishAot>true</PublishAot>
</PropertyGroup>
This will produce a self-contained native executable with:
- No .NET runtime dependency - runs on machines without .NET installed
- Fast startup - native code execution from the start
- Small binary size - approximately 4-5MB for a minimal application
- AOT-safe - all worker registration happens via source generators, no reflection
See the MinimalWorker.Aot.Sample project for a complete example.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. 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. |
-
net8.0
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.4)
- NCrontab (>= 3.3.3)
-
net9.0
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.4)
- NCrontab (>= 3.3.3)
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 |
|---|---|---|
| 3.1.5 | 447 | 2/12/2026 |
| 3.1.4 | 102 | 1/31/2026 |
| 3.1.3 | 108 | 1/19/2026 |
| 3.1.2 | 350 | 1/18/2026 |
| 3.1.1 | 1,059 | 12/27/2025 |
| 3.1.0 | 190 | 12/22/2025 |
| 3.0.0 | 482 | 12/10/2025 |
| 2.0.7 | 439 | 12/10/2025 |
| 2.0.5 | 441 | 12/10/2025 |
| 2.0.3 | 451 | 12/10/2025 |
| 2.0.2 | 437 | 12/9/2025 |
| 2.0.1 | 441 | 12/9/2025 |
| 2.0.0 | 443 | 12/9/2025 |
| 1.0.16 | 427 | 4/27/2025 |
| 1.0.13 | 229 | 4/27/2025 |
| 1.0.10 | 195 | 4/27/2025 |
| 1.0.1 | 208 | 4/27/2025 |
| 1.0.0 | 225 | 4/27/2025 |
| 0.0.8 | 198 | 4/27/2025 |
| 0.0.6 | 236 | 4/24/2025 |