MinimalWorker 1.0.16

dotnet add package MinimalWorker --version 1.0.16
                    
NuGet\Install-Package MinimalWorker -Version 1.0.16
                    
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="1.0.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MinimalWorker" Version="1.0.16" />
                    
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 1.0.16
                    
#r "nuget: MinimalWorker, 1.0.16"
                    
#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@1.0.16
                    
#: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=1.0.16
                    
Install as a Cake Addin
#tool nuget:?package=MinimalWorker&version=1.0.16
                    
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 two 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.MapBackgroundWorker(async (MyService service, CancellationToken token) =>
{
    while (!token.IsCancellationRequested)
    {
        await service.DoWorkAsync();
        await Task.Delay(1000, token);
    }
});

Periodic Background Worker

app.MapPeriodicBackgroundWorker(TimeSpan.FromMinutes(5), async (MyService service, CancellationToken token) =>
{
    await service.CleanupAsync();
});

Command run on notice (Cron) Background Worker

app.MapCronBackgroundWorker("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.

๐Ÿ”ง How It Works

  • MapBackgroundWorker runs a background task once the application starts, and continues until shutdown.
  • MapPeriodicBackgroundWorker runs your task repeatedly at a fixed interval using PeriodicTimer.
  • MapCronBackgroundWorker runs your task repeatedly based on a CRON expression (UTC time), using NCrontab for timing.
  • Services and parameters are resolved per execution using CreateScope() to support scoped dependencies.
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
1.0.16 192 4/27/2025
1.0.13 159 4/27/2025
1.0.10 151 4/27/2025
1.0.1 138 4/27/2025
1.0.0 163 4/27/2025
0.0.8 140 4/27/2025
0.0.6 163 4/24/2025
0.0.5 163 4/23/2025
0.0.4 169 4/23/2025
0.0.1 162 4/23/2025