DKNet.AspCore.Tasks
10.0.27
dotnet add package DKNet.AspCore.Tasks --version 10.0.27
NuGet\Install-Package DKNet.AspCore.Tasks -Version 10.0.27
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="DKNet.AspCore.Tasks" Version="10.0.27" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DKNet.AspCore.Tasks" Version="10.0.27" />
<PackageReference Include="DKNet.AspCore.Tasks" />
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 DKNet.AspCore.Tasks --version 10.0.27
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DKNet.AspCore.Tasks, 10.0.27"
#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 DKNet.AspCore.Tasks@10.0.27
#: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=DKNet.AspCore.Tasks&version=10.0.27
#tool nuget:?package=DKNet.AspCore.Tasks&version=10.0.27
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DKNet.AspCore.Tasks
A lightweight, easy-to-use library for managing background jobs that need to run when your ASP.NET Core application starts.
Features
- Simple API to register background jobs that execute on application startup
- Jobs run in scoped lifetime with proper dependency injection
- Automatic detection and registration of background jobs via assembly scanning
- Graceful error handling - errors in one job won't affect others
- Built on top of ASP.NET Core's IHostedService for proper lifecycle management
Installation
dotnet add package DKNet.AspCore.Tasks
Quick Start
1. Create a Background Job
Implement the IBackgroundJob interface:
public class DataInitializationJob : IBackgroundJob
{
private readonly IMyService _service;
private readonly ILogger<DataInitializationJob> _logger;
public DataInitializationJob(IMyService service, ILogger<DataInitializationJob> logger)
{
_service = service;
_logger = logger;
}
public async Task RunAsync(CancellationToken cancellationToken = default)
{
_logger.LogInformation("Initializing data...");
await _service.InitializeAsync(cancellationToken);
_logger.LogInformation("Data initialization complete");
}
}
2. Register the Background Job
In your Program.cs or startup configuration:
// Register a specific job
services.AddBackgroundJob<DataInitializationJob>();
// Or scan assemblies for all IBackgroundJob implementations
services.AddBackgroundJobFrom(new[] { typeof(Program).Assembly });
How It Works
When your application starts:
- The
BackgroundJobHost(registered as a hosted service) executes all registered jobs in parallel - Each job runs in its own scoped context with proper dependency resolution
- Errors in individual jobs are caught and logged, ensuring other jobs still complete
- All jobs must finish before the host reports completion
Advanced Usage
Multiple Jobs
Register multiple jobs individually:
services.AddBackgroundJob<FirstJob>();
services.AddBackgroundJob<SecondJob>();
services.AddBackgroundJob<ThirdJob>();
Assembly Scanning
Automatically detect and register all IBackgroundJob implementations:
// Scan current assembly
services.AddBackgroundJobFrom(new[] { Assembly.GetExecutingAssembly() });
// Scan multiple assemblies
services.AddBackgroundJobFrom(new[] {
typeof(Program).Assembly,
typeof(ExternalComponent).Assembly
});
Best Practices
- Keep jobs focused on a single responsibility
- Use dependency injection for services needed by your jobs
- Respect cancellation tokens for graceful shutdown
- Don't block the main thread with long-running synchronous operations
- Use logging to track job execution progress and issues
Compatibility
- .NET 9.0 and above
- Compatible with ASP.NET Core and any application using Microsoft's Generic Host
License
This project is licensed under the MIT License - see the LICENSE file for details.
About
Developed by Steven Hoang.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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.
-
net10.0
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.8)
- Scrutor (>= 7.0.0)
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 |
|---|---|---|
| 10.0.27 | 98 | 5/22/2026 |
| 10.0.26 | 95 | 5/19/2026 |
| 10.0.25 | 131 | 3/27/2026 |
| 10.0.24 | 108 | 3/27/2026 |
| 10.0.23 | 105 | 3/27/2026 |
| 10.0.22 | 102 | 3/26/2026 |
| 10.0.21 | 132 | 3/17/2026 |
| 10.0.20 | 119 | 2/2/2026 |
| 10.0.19 | 124 | 1/21/2026 |
| 10.0.18 | 128 | 1/21/2026 |
| 10.0.17 | 122 | 1/19/2026 |
| 10.0.16 | 115 | 1/18/2026 |
| 10.0.15 | 117 | 1/18/2026 |
| 10.0.14 | 120 | 1/18/2026 |
| 10.0.13 | 113 | 1/17/2026 |
| 10.0.12 | 115 | 1/17/2026 |
| 10.0.11 | 123 | 1/17/2026 |
| 10.0.10 | 120 | 1/17/2026 |
| 10.0.9 | 115 | 1/16/2026 |
| 10.0.8 | 117 | 1/16/2026 |
Loading failed