Skip to content

Latest commit

 

History

History

stashbox-hangfire

stashbox-hangfire

Appveyor build status Travis CI build status NuGet Version

This project provides Stashbox integration for Hangfire, using Stashbox container and Scopes to resolve jobs and their dependencies.

Common usage

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);

ASP.NET Core

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();
}

.NET Generic Host

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
}