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
<PackageReference Include="Fusonic.Extensions.Hangfire" Version="11.0.0" />
<PackageVersion Include="Fusonic.Extensions.Hangfire" Version="11.0.0" />
<PackageReference Include="Fusonic.Extensions.Hangfire" />
paket add Fusonic.Extensions.Hangfire --version 11.0.0
#r "nuget: Fusonic.Extensions.Hangfire, 11.0.0"
#:package Fusonic.Extensions.Hangfire@11.0.0
#addin nuget:?package=Fusonic.Extensions.Hangfire&version=11.0.0
#tool nuget:?package=Fusonic.Extensions.Hangfire&version=11.0.0
Hangfire
Package: Fusonic.Extensions.Hangfire (namespace Fusonic.Extensions.Hangfire)
- Out-of-band processing of commands and notifications
- Job display names
- DisableHangfireDashboardAuthorizationFilter
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
IBackgroundJobClientcan be resolved. With Microsoft DI useservices.AddHangfire(...)fromHangfire.NetCoreorHangfire.AspNetCore(not referenced by this package). - An
Fusonic.Extensions.Common.Security.IUserAccessoris registered. It gets decorated withHangfireUserAccessorDecorator, which provides the user of the caller inside the job. With ASP.NET Core,HttpContextUserAccessorfromFusonic.Extensions.AspNetCorecan 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 theIUserAccessoras scoped. Do not inject it into singletons.- Hangfire resolves the
ServiceProviderJobProcessorfrom theIServiceProvider(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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Fusonic.Extensions.Common (>= 11.0.0)
- Fusonic.Extensions.Mediator (>= 11.0.0)
- Hangfire.Core (>= 1.8.25)
- Newtonsoft.Json (>= 13.0.4)
- Scrutor (>= 7.0.0)
- SimpleInjector (>= 5.6.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 |
|---|---|---|
| 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 |