This project provides Stashbox integration for Hangfire, using Stashbox container and Scopes to resolve jobs and their dependencies.
To integrate Stashbox as the default JobActivator
into Hangfire, you can use the UseStashboxActivator
extension method on the IGlobalConfiguration
interface.
var container = new StashboxContainer();
GlobalConfiguration.Configuration.UseStashboxActivator(container);
The ASP.NET Core extension of Hangfire uses the built-in IServiceProvider
to resolve jobs through an AspNetCoreJobActivator
, so for using Stashbox as the default job activator you can simply just use the ASP.NET Core integration of Stashbox which replaces the default IServiceProvider
with a Stashbox container.
However you also have the option to tell Hangfire that it should use the StashboxJobActivator
directly.
public IServiceProvider ConfigureService(IServiceCollection services)
{
services.AddHangfire((provider, config) =>
config.UseStashboxActivator(provider.GetService<IDependencyResolver>()));
return services.UseStashbox();
}
using (var host = new HostBuilder()
.UseStashbox()
.ConfigureContainer<IStashboxContainer>((context, container) =>
{
container.Register<JobActivator, StashboxJobActivator>();
})
.ConfigureServices((context, services) =>
{
services.AddHangfireServer();
})
.Build())
{
// start and use your host
}