Hangfire
Hangfire copied to clipboard
Please use IServiceCollection.AddHangfireServer extension method instead in the ConfigureServices method. Will be removed in 2.0.0.
When I try use UseHangfireServer i get method obslete message and I'm notified I should use AddHangfireServer instead.
Seems like those two method act differently as the first one create BackgroundJobServer starts it and registers it into
requiredService.ApplicationStopping.Register((Action) (() => server.SendStop()));
requiredService.ApplicationStopped.Register((Action) (() => server.Dispose()));
This means when called a new server will be available
The AddHangfireServer on the other hand rehisters just a new service in the IServiceCollection and does not start a new server. My expectation was those methos do not act differntly when replaced.
Server handling seem to be something which might be improved in next versions of Hangfire.
The following APIs were expected to be used to tell application components that application is about to be stopped in the early versions of .NET Core, that's why UseHangfireServer method used them.
requiredService.ApplicationStopping.Register((Action) (() => server.SendStop())); requiredService.ApplicationStopped.Register((Action) (() => server.Dispose()));
Now IHostedService interface is a preferable method of starting/stopping background services in a .NET Core application, that's why AddHangfireServer uses this interface now.
From user's perspective they are identical and do the same – allow to register hooks that will be called during application shutdown.