Hangfire Integration

    Introduction

    Hangfire is a compherensive background job manager. You can integrate ASP.NET Boilerplate with Hangfire to use it instead of default background job manager. You can use the same background job API for Hangfire. Thus, your code will be independent of Hangfire. But, if you like, you can directly use Hangfire's API also.

    Integration

    First, install Abp.HangFire nuget package to your project. Then you can install any storage for Hangfire. Most common one is SQL Server storage (see Hangfire.SqlServer nuget package). After you installed these nuget packages, you can configure ASP.NET Boilerplate to use Hangfire as shown below:

    [DependsOn(typeof (AbpHangfireModule))]
    public class MyProjectWebModule : AbpModule
    {
        public override void PreInitialize()
        {
            Configuration.BackgroundJobs.UseHangfire(configuration =>
            {
                configuration.GlobalConfiguration.UseSqlServerStorage("Default");
            });
    				
        }
    
        //...
    }

    We added AbpHangfireModule as a dependency and used Configuration.BackgroundJobs.UseHangfire method to enable and configure Hangfire ("Default" is the connection string in web.config).

    Hangfire requires schema creation permission in your database since it creates it's own schema and tables on first run. See Hangfire documentation for more information.

    HangFire Dashboard Authorization

    Hagfire can show a dashboard page to see status of all background jobs in real time. You can configure it as described in it's documentation. By default, this dashboard page is available for all users, not authorized. You can integrate it to ABP's authorization system using AbpHangfireAuthorizationFilter class defined in Abp.HangFire package. Example configuration:

    app.UseHangfireDashboard("/hangfire", new DashboardOptions
    {
        Authorization = new[] { new AbpHangfireAuthorizationFilter() }
    });

    This checks if current user has logged in to the application. If you want to require an additional permission, you can pass into it's constructor:

    app.UseHangfireDashboard("/hangfire", new DashboardOptions
    {
        Authorization = new[] { new AbpHangfireAuthorizationFilter("MyHangFireDashboardPermissionName") }
    });

    Note: UseHangfireDashboard should be called after authentication middleware in your Startup class (probably as the last line). Otherwise, authorization always fails.