in src/Microsoft.Azure.SignalR.Management/DependencyInjectionExtensions.cs [83:133]
private static IServiceCollection AddSignalRServiceCore(this IServiceCollection services)
{
services.AddSingleton<IServiceManager, ServiceManagerImpl>();
services.PostConfigure<ServiceManagerOptions>(o => o.ValidateOptions());
var tempServices = new ServiceCollection()
.AddSingleton<IEndpointRouter, AutoHealthCheckRouter>()
.AddSignalR()
.AddAzureSignalR<CascadeServiceOptionsSetup>().Services
.Where(service => service.ServiceType != typeof(IServiceConnectionContainer))
.Where(service => service.ServiceType != typeof(IHostedService));
services.Add(tempServices);
// Remove the JsonHubProtocol and add new one.
// On .NET Standard 2.0, registering multiple hub protocols with the same name is forbidden.
services.Replace(ServiceDescriptor.Singleton<IHubProtocol>(sp =>
{
var serviceManagerOptions = sp.GetRequiredService<IOptions<ServiceManagerOptions>>().Value;
var objectSerializer = serviceManagerOptions.ObjectSerializer;
if (objectSerializer != null)
{
return new JsonObjectSerializerHubProtocol(objectSerializer);
}
#pragma warning disable CS0618 // Type or member is obsolete
// The default protocol is different for historical reason.
return serviceManagerOptions.ServiceTransportType == ServiceTransportType.Transient ?
new JsonObjectSerializerHubProtocol(new NewtonsoftJsonObjectSerializer(serviceManagerOptions.JsonSerializerSettings))
:
new JsonHubProtocol();
#pragma warning restore CS0618 // Type or member is obsolete
}));
//add dependencies for persistent mode only
services
.AddSingleton<ConnectionFactory>()
.AddSingleton<IConnectionFactory, ManagementConnectionFactory>()
.AddSingleton<ConnectionDelegate>((connectionContext) => Task.CompletedTask)
.AddSingleton<IServiceConnectionFactory, ServiceConnectionFactory>()
.AddSingleton<MultiEndpointConnectionContainerFactory>()
.AddSingleton<IConfigureOptions<HubOptions>, ManagementHubOptionsSetup>();
//add dependencies for transient mode only
services.AddSingleton<PayloadBuilderResolver>();
services.AddRestClient();
services.AddSingleton<NegotiateProcessor>();
#if NET7_0_OR_GREATER
services.AddSingleton<IClientInvocationManager, WeakClientInvocationManager>();
#else
services.AddSingleton<IClientInvocationManager, DummyClientInvocationManager>();
#endif
return services.TrySetProductInfo();
}