Starts in:
0 DAY
21 HRS
31 MIN
52 SEC
Starts in:
0 D
21 H
31 M
52 S

Hangfire Background Job Manager

Hangfire is an advanced background job manager. You can integrate Hangfire with the ABP Framework to use it instead of the default background job manager. In this way, you can use the same background job API for Hangfire and your code will be independent of Hangfire. If you like, you can directly use Hangfire's API, too.

See the background jobs document to learn how to use the background job system. This document only shows how to install and configure the Hangfire integration.

Installation

It is suggested to use the ABP CLI to install this package.

Using the ABP CLI

Open a command line window in the folder of the project (.csproj file) and type the following command:

abp add-package Volo.Abp.BackgroundJobs.HangFire

Manual Installation

If you want to manually install;

  1. Add the Volo.Abp.BackgroundJobs.HangFire NuGet package to your project:

    Install-Package Volo.Abp.BackgroundJobs.HangFire
    
  2. Add the AbpBackgroundJobsHangfireModule to the dependency list of your module:

[DependsOn(
    //...other dependencies
    typeof(AbpBackgroundJobsHangfireModule) //Add the new module dependency
    )]
public class YourModule : AbpModule
{
}

Configuration

You can install any storage for Hangfire. The most common one is SQL Server (see the Hangfire.SqlServer NuGet package).

After you have installed these NuGet packages, you need to configure your project to use Hangfire.

1.First, we change the Module class (example: <YourProjectName>HttpApiHostModule) to add Hangfire configuration of the storage and connection string in the ConfigureServices method:

  public override void ConfigureServices(ServiceConfigurationContext context)
  {
      var configuration = context.Services.GetConfiguration();
      var hostingEnvironment = context.Services.GetHostingEnvironment();

      //... other configarations.

      ConfigureHangfire(context, configuration);
  }

  private void ConfigureHangfire(ServiceConfigurationContext context, IConfiguration configuration)
  {
      context.Services.AddHangfire(config =>
      {
          config.UseSqlServerStorage(configuration.GetConnectionString("Default"));
      });
  }
  1. We need to add UseHangfireServer call in the OnApplicationInitialization method in Module class

If you want to use hangfire's dashboard, you can add it, too: by UseHangfireDashboard

 public override void OnApplicationInitialization(ApplicationInitializationContext context)
 {
    var app = context.GetApplicationBuilder();
            
    // ... others
    
    app.UseHangfireServer();
    app.UseHangfireDashboard();
 
 }

Was this page helpful?

Please make a selection.

To help us improve, please share your reason for the negative feedback in the field below.

Please enter a note.

Thank you for your valuable feedback!

Please note that although we cannot respond to feedback, our team will use your comments to improve the experience.

In this document
Community Talks

What’s New with .NET 9 & ABP 9?

21 Nov, 17:00
Online
Watch the Event
Mastering ABP Framework Book
Mastering ABP Framework

This book will help you gain a complete understanding of the framework and modern web application development techniques.

Learn More