Everything was working ok until I move to different dev machine. I'm getting the following error:
System.InvalidOperationException: 'JobStorage.Current property value has not been
initialized. You must set it before using Hangfire Client or Server API.'
I have my mongo running, and I didn't change anything. This is how I add things,
services.AddHangfire(x => x.UseMongoStorage(conString, databaseName);
services.AddScoped<IBackgroundJobClient, BackgroundJobClient>();
I inject IBackgroundJobClient , and do
_client.Enqueue(() => MethodEnqueued(...));
What puzzles me is that I didn't change anything, and everything was working fine few hours ago.
Hangfire.AspNetCore v1.6.12, Hangfire.Mongo v0.3.2
Remove the following line:
services.AddScoped<IBackgroundJobClient, BackgroundJobClient>();
The AddHangfire() method already registers a correct IBackgroundJobClient implementation, so you don't need to. With that line, you override it with a default-constructed BackgroundJobClient (which uses static property JobStorage.Current instead of resolving it from service container), so you get the error.
Most helpful comment
Remove the following line:
The
AddHangfire()method already registers a correctIBackgroundJobClientimplementation, so you don't need to. With that line, you override it with a default-constructedBackgroundJobClient(which uses static propertyJobStorage.Currentinstead of resolving it from service container), so you get the error.