Being forced to DI a IRecurringJobManager to ensure Hangfire initialised

Tags: #<Tag:0x00007f7b598baa70> #<Tag:0x00007f7b598ba6b0>

I’m trying to schedule a simple recurring job from one of my classes in an ASP.NET core 3.1 app backed up by Mongo storage.

When I try to just call RecurringJob.AddOrUpdate, however, I get a jobstorage.current property value has not been initialized error. I note that the configuration code within the configuration block isn’t being called:

            services.AddHangfire(
            configuration => configuration
               .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
               .UseSimpleAssemblyNameTypeSerializer()
               .UseRecommendedSerializerSettings()
               .UseSerilogLogProvider()
               .UseMongoStorage(
                    this.configuration.GetMongoUrl().ToString(),
                    new MongoStorageOptions
                    {
                        // we don't have critical tasks that need to be persisted across upgrades, we can drop with no backup
                        MigrationOptions = new MongoMigrationOptions
                        {
                            MigrationStrategy = new DropMongoMigrationStrategy()
                        },
                        Prefix = "hangfire.mongo",
                        CheckConnection = true
                    }));

        services.AddHangfireServer();

If I attempt to inject IRecurringJobManager into the class trying to schedule the job and instead call injectedJobManager.AddOrUpdate<T>(...) the configuration code is called as expected and the application runs.

Am I missing a step in configuring the application? I’m not running Dashboard, but have got all the code on ASP.NET Core Applications — Hangfire Documentation under ‘registering services’