Differences between AddSignalR and AddSignalRCore extension methods in aspnet core 2.1

Viewed 5431

I 'm trying to configure SignalR in my aspnet core 2.1 project.In Startup.cs class ,in ConfigureServices() method there are 2 options to use.

services.AddSignalR()
services.AddSignalRCore()

What are the differences between these 2 methods?

I was easily able to work with signalR with services.AddSignalR() but when i changed it to services.AddSignalRCore() it throw an error.

1 Answers

AddSignalR() calls two more additional services than AddSignalRCore() as follows:

Here is the code of AddSignalR() method:

public static ISignalRBuilder AddSignalR(this IServiceCollection services, Action<HubOptions> configure)
{
    services.Configure(configure);
    services.AddSockets();
    return services.AddSignalRCore();
}

And here is the code of AddSignalRCore() method:

public static ISignalRBuilder AddSignalRCore(this IServiceCollection services)
{
    services.AddSingleton(typeof(HubLifetimeManager<>), typeof(DefaultHubLifetimeManager<>));
    services.AddSingleton(typeof(IHubProtocolResolver), typeof(DefaultHubProtocolResolver));
    services.AddSingleton(typeof(IHubContext<>), typeof(HubContext<>));
    services.AddSingleton(typeof(HubEndPoint<>), typeof(HubEndPoint<>));
    services.AddScoped(typeof(IHubActivator<>), typeof(DefaultHubActivator<>));
    
    services.AddAuthorization();
    
    return new SignalRBuilder(services);
}
Related