From fa702ff6ef53ce483c7b87fb6720911fe6267ccc Mon Sep 17 00:00:00 2001 From: Mikael Mengistu Date: Thu, 7 Jun 2018 16:32:37 -0700 Subject: [PATCH] Update AddSignalRCore to respect user registered services (#2434) --- .../SignalRDependencyInjectionExtensions.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNetCore.SignalR.Core/SignalRDependencyInjectionExtensions.cs b/src/Microsoft.AspNetCore.SignalR.Core/SignalRDependencyInjectionExtensions.cs index 3e5587cc5b..3271883a0a 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/SignalRDependencyInjectionExtensions.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/SignalRDependencyInjectionExtensions.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR.Internal; +using Microsoft.Extensions.DependencyInjection.Extensions; namespace Microsoft.Extensions.DependencyInjection { @@ -20,14 +21,14 @@ namespace Microsoft.Extensions.DependencyInjection public static ISignalRServerBuilder AddSignalRCore(this IServiceCollection services) { services.AddSingleton(); - services.AddSingleton(typeof(HubLifetimeManager<>), typeof(DefaultHubLifetimeManager<>)); - services.AddSingleton(typeof(IHubProtocolResolver), typeof(DefaultHubProtocolResolver)); - services.AddSingleton(typeof(IHubContext<>), typeof(HubContext<>)); - services.AddSingleton(typeof(IHubContext<,>), typeof(HubContext<,>)); - services.AddSingleton(typeof(HubConnectionHandler<>), typeof(HubConnectionHandler<>)); - services.AddSingleton(typeof(IUserIdProvider), typeof(DefaultUserIdProvider)); - services.AddSingleton(typeof(HubDispatcher<>), typeof(DefaultHubDispatcher<>)); - services.AddScoped(typeof(IHubActivator<>), typeof(DefaultHubActivator<>)); + services.TryAddSingleton(typeof(HubLifetimeManager<>), typeof(DefaultHubLifetimeManager<>)); + services.TryAddSingleton(typeof(IHubProtocolResolver), typeof(DefaultHubProtocolResolver)); + services.TryAddSingleton(typeof(IHubContext<>), typeof(HubContext<>)); + services.TryAddSingleton(typeof(IHubContext<,>), typeof(HubContext<,>)); + services.TryAddSingleton(typeof(HubConnectionHandler<>), typeof(HubConnectionHandler<>)); + services.TryAddSingleton(typeof(IUserIdProvider), typeof(DefaultUserIdProvider)); + services.TryAddSingleton(typeof(HubDispatcher<>), typeof(DefaultHubDispatcher<>)); + services.TryAddScoped(typeof(IHubActivator<>), typeof(DefaultHubActivator<>)); services.AddAuthorization(); var builder = new SignalRServerBuilder(services);