Fusonic.Extensions.Hangfire 11.0.0

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

Hangfire

Package: Fusonic.Extensions.Hangfire (namespace Fusonic.Extensions.Hangfire)

Out-of-band processing of commands and notifications

Mark a handler of the Mediator with Fusonic.Extensions.Mediator.OutOfBandAttribute. Instead of running the handler, the out-of-band decorator enqueues a Hangfire job that runs it in the background. If the Hangfire storage enlists in the current transaction, the job is only scheduled when the transaction commits. This way the business operation and the follow-up commands/notifications are stored atomically.

using Fusonic.Extensions.Mediator;

[OutOfBand]
public class SendWelcomeEmailHandler : IRequestHandler<SendWelcomeEmail>
{
    public Task<Unit> Handle(SendWelcomeEmail request, CancellationToken cancellationToken) { ... }
}

Only handlers without a response (IRequestHandler<TRequest, Unit>, e.g. for ICommand/IRequest) and notification handlers are decorated. [OutOfBand] on a handler returning a response is ignored.

The job restores the culture, UI culture and user (via IUserAccessor) of the caller before running the handler. Inside the job, the out-of-band decorator is skipped, so the handler runs directly (still wrapped by the other decorators, e.g. the transactional decorators).

Prerequisites

  • Hangfire is configured, so IBackgroundJobClient can be resolved. With Microsoft DI use services.AddHangfire(...) from Hangfire.NetCore or Hangfire.AspNetCore (not referenced by this package).
  • An Fusonic.Extensions.Common.Security.IUserAccessor is registered. It gets decorated with HangfireUserAccessorDecorator, which provides the user of the caller inside the job. With ASP.NET Core, HttpContextUserAccessor from Fusonic.Extensions.AspNetCore can be used.

Registration with SimpleInjector

The out-of-band decorator must be the innermost decorator of a handler, so it can enqueue the actual handler type. SimpleInjector applies decorators in registration order, so call RegisterOutOfBandDecorators() before RegisterMediator(...) (which registers the transactional decorators) and before any other handler decorator.

using Fusonic.Extensions.Hangfire;
using Fusonic.Extensions.Mediator;
using Hangfire;

container.Register<IUserAccessor, YourUserAccessor>(Lifestyle.Scoped);

container.RegisterOutOfBandDecorators();
container.RegisterMediator(services, [typeof(Program).Assembly]);

// Hangfire resolves the JobProcessor from the container
services.AddHangfire(c => c
    .UseActivator(new ContainerJobActivator(container))
    .UsePostgreSqlStorage(...));

// IBackgroundJobClient must be resolvable from the container, e.g. via cross-wiring
// (SimpleInjector.Integration.ServiceCollection, plus UseSimpleInjector(container) on the built service provider)
services.AddSimpleInjector(container, o => o.AutoCrossWireFrameworkComponents = true);

Registration with Microsoft.Extensions.DependencyInjection and Scrutor

Scrutor moves decorated registrations to keyed ones and hides their implementation type. Therefore register the handlers and the IUserAccessor first, then call AddOutOfBandDecorators(), then register all other handler decorators. It throws if an out-of-band handler is already decorated.

using Fusonic.Extensions.Common.Transactions;
using Fusonic.Extensions.Hangfire;
using Fusonic.Extensions.Mediator;
using Fusonic.Extensions.Mediator.DependencyInjection;

services.AddScoped<IUserAccessor, YourUserAccessor>();
services.AddTransient<IMediator>(sp => new ServiceProviderMediator(sp));

// 1. Handlers
services.Scan(s => s.FromAssemblyOf<Program>()
        .AddClasses(c => c.AssignableToAny(typeof(IRequestHandler<,>), typeof(INotificationHandler<>), typeof(IAsyncEnumerableRequestHandler<,>)))
        .AsImplementedInterfaces()
        .WithScopedLifetime());

// 2. Out-of-band decorators
services.AddOutOfBandDecorators();

// 3. Other decorators
services.TryDecorate(typeof(IRequestHandler<,>), typeof(TransactionalRequestHandlerDecorator<,>));
services.TryDecorate(typeof(INotificationHandler<>), typeof(TransactionalNotificationHandlerDecorator<>));
services.AddSingleton<ITransactionScopeHandler, TransactionScopeHandler>();

services.AddHangfire(c => c.UsePostgreSqlStorage(...));

Notes:

  • Handlers are detected by their ServiceDescriptor.ImplementationType. Handlers registered via factory or instance are not decorated.
  • AddOutOfBandDecorators() re-registers the IUserAccessor as scoped. Do not inject it into singletons.
  • Hangfire resolves the ServiceProviderJobProcessor from the IServiceProvider (Hangfire.NetCore/Hangfire.AspNetCore).

Custom job processor

Both registrations accept a custom job processor:

container.RegisterOutOfBandDecorators(o => o.UseJobProcessor<MyJobProcessor>());   // derive from JobProcessor
services.AddOutOfBandDecorators(o => o.UseJobProcessor<MyJobProcessor>());         // derive from ServiceProviderJobProcessor

The job processor must implement IJobProcessor. JobProcessorBase.ProcessAsync is virtual.

Job display names

Out-of-band jobs are shown as OutOfBand Message: <message type> (<namespace>) in the Hangfire dashboard. To show the handler type instead, use:

var dashboardOptions = new DashboardOptions { DisplayNameFunc = DashboardHelpers.FormatJobDisplayName };
app.UseHangfireDashboard(options: dashboardOptions);

DisableHangfireDashboardAuthorizationFilter

By default the Hangfire dashboard only allows local requests. This fails when the app runs in a Docker container. For local development, where you have other means of authorization, disable the authorization completely:

var dashboardOptions = new DashboardOptions { Authorization = [new DisableHangfireDashboardAuthorizationFilter()] };
app.UseHangfireDashboard(options: dashboardOptions);
Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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
11.0.0 95 11/23/2026
10.3.0 111 11/9/2026
10.2.0 105 11/5/2026
10.1.0 1,532 3/18/2026
10.0.1 165 3/17/2026
10.0.0 409 11/25/2025
10.0.0-rc.2 211 11/24/2025
10.0.0-rc.1 169 9/12/2025
9.5.4 722 8/20/2025
9.5.3 566 3/28/2025
9.5.2 761 1/16/2025
9.5.0 364 10/4/2024
9.4.0 443 9/23/2024
9.3.1 365 9/11/2024
9.3.0 300 9/11/2024
9.2.0 322 8/8/2024
9.2.0-rc.3 159 8/7/2024
9.2.0-rc.2 128 8/5/2024
9.2.0-rc.1 150 8/1/2024
9.1.0 266 7/29/2024
Loading failed