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

When using new worker service

public static IHostBuilder CreateHostBuilder(string args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddHangfireServer();
services.AddHangfire(config => config.UseSqlServerStorage(“connectionString”));
services.AddHostedService();
});

  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 : https://stackoverflow.com/questions/56112793/is-there-a-way-to-setup-queue-listening-for-hangfire-in-the-configureservices/56112933#56112933)

  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.