Hangfire: Overload `AddHangfireServer` to allow configuration of BackgroundJobServerOptions

Created on 9 Jul 2019  路  5Comments  路  Source: HangfireIO/Hangfire

It would be really convenient to add an overload to HangfireServiceCollectionExtensions.AddHangfireServer to allow configuration of BackgroundJobServerOptions like AddHangfire and GlobalConfiguration

https://github.com/HangfireIO/Hangfire/blob/master/src/Hangfire.AspNetCore/HangfireServiceCollectionExtensions.cs#L125

Current Solution:

services.AddSingleton(provider => new BackgroundJobServerOptions
{
    Queues = new[] { "default", "misc" },
    WorkerCount = 1,
});
services.AddHangfireServer();

Proposed Solution:

services.AddHangfireServer(options =>
{
    options.WorkCount = 1;
    options.Queues = new[] {"default", "misc"};
});
dotnetcore enhancement

Most helpful comment

Indeed much simpler, thanks. Just added an overload that will be available in upcoming 1.7.5.

All 5 comments

I had the same issue and wondered why there was no overload too. Would be a nice addition!

According to the docs it is an option. But it is done in the Configure method and not ConfigureServices in the Startup file of core. However using this approach is not desribed in Getting Started. I do not know what difference, if any, it makes but it might be worth a try.

@djesmond In Hangfire 1.7 the AddHangfireServer was introduced to add a IHostedService to WebHost and GenericHost of ASP.NET Core 2.1+.

I believe UseHangfireServer was built around using WebHost IApplicationLifeTime for starting and stopping. Not as clean imho

I see. So AddHangfireServer can be considered the replacement for UseHangfireServer?

Indeed much simpler, thanks. Just added an overload that will be available in upcoming 1.7.5.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeffsugden picture jeffsugden  路  4Comments

odinserj picture odinserj  路  4Comments

thurfir picture thurfir  路  4Comments

dbones picture dbones  路  3Comments

JvanderStad picture JvanderStad  路  3Comments