Muonroi.BackgroundJobs.Hangfire
1.0.0-alpha.16
dotnet add package Muonroi.BackgroundJobs.Hangfire --version 1.0.0-alpha.16
NuGet\Install-Package Muonroi.BackgroundJobs.Hangfire -Version 1.0.0-alpha.16
<PackageReference Include="Muonroi.BackgroundJobs.Hangfire" Version="1.0.0-alpha.16" />
<PackageVersion Include="Muonroi.BackgroundJobs.Hangfire" Version="1.0.0-alpha.16" />
<PackageReference Include="Muonroi.BackgroundJobs.Hangfire" />
paket add Muonroi.BackgroundJobs.Hangfire --version 1.0.0-alpha.16
#r "nuget: Muonroi.BackgroundJobs.Hangfire, 1.0.0-alpha.16"
#:package Muonroi.BackgroundJobs.Hangfire@1.0.0-alpha.16
#addin nuget:?package=Muonroi.BackgroundJobs.Hangfire&version=1.0.0-alpha.16&prerelease
#tool nuget:?package=Muonroi.BackgroundJobs.Hangfire&version=1.0.0-alpha.16&prerelease
Muonroi.BackgroundJobs.Hangfire
Hangfire provider for the Muonroi background-jobs rail — wires
IBackgroundJobSchedulerto Hangfire with automatic execution-context restoration per job run.
This package implements the IBackgroundJobScheduler abstraction (defined in Muonroi.BackgroundJobs.Abstractions) using Hangfire as the backing engine. It registers itself as a provider at module load time, so AddBackgroundJobs(configuration) dispatches to Hangfire automatically when BackgroundJobConfigs.JobType is set to Hangfire. A built-in JobContextActivatorFilter restores the Muonroi execution context (tenant ID, user, correlation ID, permissions) for every job before it runs.
Installation
dotnet add package Muonroi.BackgroundJobs.Hangfire --prerelease
License required. This is a commercial package. A valid Muonroi commercial license must be accepted at install time (
PackageRequireLicenseAcceptance = true).
Quick Start
// Program.cs — based on samples/Quickstart.BackgroundJobs
using Hangfire;
using Hangfire.MemoryStorage; // swap for SqlServer/Postgres in production
using Muonroi.BackgroundJobs.Abstractions;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// 1. Configure Hangfire storage (before AddBackgroundJobs).
builder.Services.AddHangfire(config =>
config.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseMemoryStorage()); // production: UseSqlServerStorage(cs) etc.
// 2. Register the Muonroi BackgroundJobs rail.
// Reads "BackgroundJobConfigs" section; dispatches to the Hangfire provider.
builder.Services.AddBackgroundJobs(builder.Configuration);
// 3. Register your job classes (Hangfire resolves them from DI).
builder.Services.AddTransient<ReportEmailJob>();
builder.Services.AddTransient<DataCleanupJob>();
WebApplication app = builder.Build();
// 4. Mount Hangfire middleware.
app.UseHangfireDashboard("/hangfire");
app.UseHangfireServer();
app.Run();
Inject IBackgroundJobScheduler wherever you need to dispatch work:
public class OrderService(IBackgroundJobScheduler jobs)
{
public async Task PlaceOrderAsync(Order order)
{
// Fire-and-forget
jobs.Enqueue<InvoiceJob>(j => j.SendAsync(order.Id));
// Delayed one-shot
jobs.Schedule<ArchiveJob>(
j => j.RunAsync(order.Id),
DateTimeOffset.UtcNow.AddDays(30));
// Recurring
jobs.AddOrUpdateRecurring<DataCleanupJob>(
"nightly-cleanup",
j => j.RunAsync(),
Cron.Daily());
}
}
appsettings.json
{
"BackgroundJobConfigs": {
"JobType": "Hangfire",
"ConnectionString": null
}
}
Features
- Implements
IBackgroundJobSchedulervia Hangfire (IBackgroundJobClient+IRecurringJobManager). - Fire-and-forget —
Enqueue<T>(Expression<Func<T, Task>>). - Delayed one-shot —
Schedule<T>(Expression<Func<T, Task>>, DateTimeOffset). - Recurring (CRON) —
AddOrUpdateRecurring<T>(id, expression, cronExpression). - Cancel recurring —
RemoveRecurring(id). - Automatic retry — 3 attempts with delays of 5 s / 10 s / 30 s, configured globally via
AutomaticRetryAttribute. - Execution-context restoration —
JobContextActivatorFilter(auto-registered as anIServerFilter) extractsIMuonroiJobExecutionContextfrom job arguments and restores tenant ID, user ID, correlation ID, access token, permissions, and log scope beforeOnPerforming, disposes all scopes inOnPerformed. - Provider registration via
[ModuleInitializer]— loading this assembly callsBackgroundJobHandler.RegisterProvider(JobType.Hangfire, ...)automatically; no explicit provider wiring needed. - Hangfire Dashboard — expose at any path via
app.UseHangfireDashboard("/hangfire").
Configuration
AddBackgroundJobs(IConfiguration) reads the BackgroundJobConfigs section:
| Key | Type | Default | Purpose |
|---|---|---|---|
BackgroundJobConfigs:JobType |
JobType enum |
Hangfire |
Must be Hangfire for this package; throws MConfigurationException otherwise. |
BackgroundJobConfigs:ConnectionString |
string? |
null |
Passed to your Hangfire storage setup (not consumed by this package directly — configure storage via AddHangfire). |
The section name constant is BackgroundJobConfigs.SectionName ("BackgroundJobConfigs").
API Reference
| Type | Purpose |
|---|---|
BackgroundJobHandler (static) |
Extension class hosting AddBackgroundJobs(IServiceCollection, IConfiguration) — the single DI entry point. |
HangfireJobScheduler |
IBackgroundJobScheduler implementation backed by IBackgroundJobClient and IRecurringJobManager. |
JobContextActivatorFilter |
Hangfire IServerFilter that restores ISystemExecutionContext (tenant, user, correlation) before each job executes. |
BackgroundJobConfigs |
Options POCO bound from the BackgroundJobConfigs appsettings section; exposes JobType and ConnectionString. |
Samples
- Quickstart.BackgroundJobs — end-to-end demo: fire-and-forget, delayed, recurring, cancel recurring, tenant-aware jobs, plain jobs, and the Hangfire Dashboard.
Compatibility
- Target framework:
net8.0 - License: Commercial — requires activation (see LICENSE-COMMERCIAL)
Related Packages
Muonroi.BackgroundJobs.Abstractions—IBackgroundJobScheduler,IMuonroiJobExecutionContext,JobType, and the provider-dispatch mechanism. Required peer dependency.
License
This package is distributed under the Muonroi Commercial License. License acceptance is required at install time. Contact leanhphi1706@gmail.com for licensing details.
| 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 was computed. 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
- Hangfire.AspNetCore (>= 1.8.21)
- Hangfire.Core (>= 1.8.21)
- Muonroi.BackgroundJobs.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.Core.Abstractions (>= 1.0.0-alpha.16)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Muonroi.BackgroundJobs.Hangfire:
| Package | Downloads |
|---|---|
|
Muonroi.BuildingBlock.All
Metapackage for Muonroi Building Block - Includes all sub-packages for a complete infrastructure setup. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.16 | 70 | 6/22/2026 |
| 1.0.0-alpha.15 | 82 | 5/31/2026 |
| 1.0.0-alpha.14 | 86 | 5/15/2026 |
| 1.0.0-alpha.13 | 78 | 5/2/2026 |
| 1.0.0-alpha.12 | 79 | 4/2/2026 |
| 1.0.0-alpha.11 | 124 | 4/2/2026 |
| 1.0.0-alpha.8 | 163 | 3/28/2026 |
| 1.0.0-alpha.1 | 73 | 3/8/2026 |