How to use Hangfire with new worker in .NET core 3?

Tags: #<Tag:0x00007f499ab90650> #<Tag:0x00007f499ab90510>


When using new worker service

public static IHostBuilder CreateHostBuilder(string[] args) =>
.ConfigureServices(services =>
services.AddHangfire(config => config.UseSqlServerStorage(“connectionString”));

  1. How do I pass in BackgroundJobServerOptions?

  2. How can I queue all my recurring jobs in this setup? I can do it by calling GlobalConfiguration.Configuration.UseSqlServerStorage and RecurringJob.AddOrUpdate but I’d like to avoid calling static methods. Can it be done?

  1. I you want to pass BackgroundJobServerOptions, you need to inject it before calling AddHangfireServer(); (see :

  2. If you don’t want to use RecurringJob.AddOrUpdate, you can use the class RecurringJobManager. Here’s the documentation about recurrent Tasks

  1. It was added in a later version. Thanks
  2. If we just create new RecurringJobManager it will work?


I would retrieve it from injection after setting up hangfire completely and it should be properly configured.