From 3bfe1e03748de1fa86b736f94bb7e57422e8ef53 Mon Sep 17 00:00:00 2001 From: Krzysztof Blacha Date: Fri, 22 Jul 2022 17:28:48 +0200 Subject: [PATCH] Changed service registration from Transient to Singleton to able consume it --- .../HangfireServiceCollectionExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Hangfire.AspNetCore/HangfireServiceCollectionExtensions.cs b/src/Hangfire.AspNetCore/HangfireServiceCollectionExtensions.cs index 6f13a485e..66f2b151f 100644 --- a/src/Hangfire.AspNetCore/HangfireServiceCollectionExtensions.cs +++ b/src/Hangfire.AspNetCore/HangfireServiceCollectionExtensions.cs @@ -182,7 +182,7 @@ private static IServiceCollection AddHangfireServerInner( [CanBeNull] JobStorage storage, [CanBeNull] IEnumerable additionalProcesses) { - services.AddTransient(provider => + services.AddSingleton(provider => { var options = provider.GetService() ?? new BackgroundJobServerOptions(); return CreateBackgroundJobServerHostedService(provider, storage, additionalProcesses, options); @@ -197,7 +197,7 @@ private static IServiceCollection AddHangfireServerInner( [CanBeNull] IEnumerable additionalProcesses, [NotNull] Action optionsAction) { - services.AddTransient(provider => + services.AddSingleton(provider => { var options = new BackgroundJobServerOptions(); optionsAction(provider, options);