Muonroi.BackgroundJobs.Hangfire 1.0.0-alpha.16

This is a prerelease version of Muonroi.BackgroundJobs.Hangfire.
dotnet add package Muonroi.BackgroundJobs.Hangfire --version 1.0.0-alpha.16
                    
NuGet\Install-Package Muonroi.BackgroundJobs.Hangfire -Version 1.0.0-alpha.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="Muonroi.BackgroundJobs.Hangfire" Version="1.0.0-alpha.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muonroi.BackgroundJobs.Hangfire" Version="1.0.0-alpha.16" />
                    
Directory.Packages.props
<PackageReference Include="Muonroi.BackgroundJobs.Hangfire" />
                    
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 Muonroi.BackgroundJobs.Hangfire --version 1.0.0-alpha.16
                    
#r "nuget: Muonroi.BackgroundJobs.Hangfire, 1.0.0-alpha.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 Muonroi.BackgroundJobs.Hangfire@1.0.0-alpha.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=Muonroi.BackgroundJobs.Hangfire&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Muonroi.BackgroundJobs.Hangfire&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Tool

Muonroi.BackgroundJobs.Hangfire

Hangfire provider for the Muonroi background-jobs rail — wires IBackgroundJobScheduler to Hangfire with automatic execution-context restoration per job run.

NuGet License: Commercial

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 IBackgroundJobScheduler via Hangfire (IBackgroundJobClient + IRecurringJobManager).
  • Fire-and-forgetEnqueue<T>(Expression<Func<T, Task>>).
  • Delayed one-shotSchedule<T>(Expression<Func<T, Task>>, DateTimeOffset).
  • Recurring (CRON)AddOrUpdateRecurring<T>(id, expression, cronExpression).
  • Cancel recurringRemoveRecurring(id).
  • Automatic retry — 3 attempts with delays of 5 s / 10 s / 30 s, configured globally via AutomaticRetryAttribute.
  • Execution-context restorationJobContextActivatorFilter (auto-registered as an IServerFilter) extracts IMuonroiJobExecutionContext from job arguments and restores tenant ID, user ID, correlation ID, access token, permissions, and log scope before OnPerforming, disposes all scopes in OnPerformed.
  • Provider registration via [ModuleInitializer] — loading this assembly calls BackgroundJobHandler.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)

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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