Open kamran-pervaiz opened 6 years ago
I have fixed it with below code but it would be great if we have the ability to clear GlobalConfiguration for HangFire.
if (AlreadyConfiguredHangFireConsole) return;
GlobalConfiguration.Configuration
.UseConsole();
AlreadyConfiguredHangFireConsole = true;
I solved this problem by using the singleton pattern. My singleton is called HangfireGlobalConfiguration
and I simply call HangfireGlobalConfiguration.GetInstance()
in my OwinStartup
method. Inside that class I setup sql server storage and console.
The benefits of using that pattern is you can make it thread safe and lazy, where your above code is not.
But why rely on statics in the first place? It makes it a pain to test.
Is there any progress on refactoring out the singleton state stores (e.g. GlobalConfiguration)?
Hangfire and its extensions, as useful as they are, do rely too much on static state in GlobalConfiguration.Configuration, JobStorage.Current, JobActivator.Current, causing problems when multiple IServiceCollections are initialized. The actual issue is tracked in #821, I believe.
I am setting up test project and when I am running my tests I get below error.
I know the issue lies in below code:
GlobalConfiguration.Configuration.UseConsole();
This error message is added in 1.3.10
but not sure what is elegant way to stop calling UseConsole() more than once. This code is written as part of HangFireConfiguration class. can we clear HangFire GlobalConfiguration?