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

Tags: #<Tag:0x00007f49ac031900> #<Tag:0x00007f49ac0317c0>


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