MinimalWorker 2.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package MinimalWorker --version 2.0.2
                    
NuGet\Install-Package MinimalWorker -Version 2.0.2
                    
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="MinimalWorker" Version="2.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MinimalWorker" Version="2.0.2" />
                    
Directory.Packages.props
<PackageReference Include="MinimalWorker" />
                    
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 MinimalWorker --version 2.0.2
                    
#r "nuget: MinimalWorker, 2.0.2"
                    
#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 MinimalWorker@2.0.2
                    
#: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=MinimalWorker&version=2.0.2
                    
Install as a Cake Addin
#tool nuget:?package=MinimalWorker&version=2.0.2
                    
Install as a Cake Tool

MinimalWorker

Publish NuGet Package NuGet Downloads NuGet Version

Worker

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

  • RunBackgroundWorker runs a background task once the application starts, and continues until shutdown.
  • RunPeriodicBackgroundWorker runs your task repeatedly at a fixed interval using PeriodicTimer.
  • RunCronBackgroundWorker runs 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 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. 
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
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
Loading failed