Hangfire icon indicating copy to clipboard operation
Hangfire copied to clipboard

IServiceCollection.AddHangfireServer example configuration

Open famda opened this issue 2 years ago • 4 comments

Hi all,

I'm using Hangfire for quite some time. Is it possible to provide the new configuration for the extension method IServiceCollection AddHanfireServer to pass additional processes and a BackgroundJobServerOptions instance to this new method?

The previous method (IApplicationBuilder AddHangfireServer) is now obsolete and now it requires a NotNull instance of JobStorage on ConfigureServices method.

image

image

@odinserj

famda avatar Dec 23 '21 12:12 famda

Any class registered in the DI as IBackgroundProcess is automatically added as an additional service. See CreateBackgroundJobServerHostedService method

akarboush avatar Jan 14 '22 09:01 akarboush

@akarboush

What??

famda avatar Jan 16 '22 18:01 famda

What I meant, just use the AddHanfireServer method that takes optionsAction and no JobStorage as parameter

public static IServiceCollection AddHangfireServer(
            [NotNull] this IServiceCollection services,
            [NotNull] Action<IServiceProvider, BackgroundJobServerOptions> optionsAction)
{ ...... }

then add any additional services by registering them as IBackgroundProcess in the DI Container. You could create an extension method for it if you want to

akarboush avatar Jan 18 '22 09:01 akarboush

Oh. I see. You mean something like this instead of the commented?

image

This seems to work.. :)

famda avatar Jan 18 '22 10:01 famda