Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between AddSignalR and AddSignalRCore extension methods in aspnet core 2.1

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.

like image 703
dev pishgaman Avatar asked Dec 31 '18 08:12

dev pishgaman


People also ask

Which package is used for SignalR?

SignalR. Client NuGet package contains the . NET client libraries for ASP.NET Core SignalR. Use the HubConnectionBuilder to create and build an instance of a connection to a hub.

What is single R in asp net?

Real-time web functionality is the ability to have server code push content to connected clients instantly as it becomes available, rather than having the server wait for a client to request new data. SignalR can be used to add any sort of "real-time" web functionality to your ASP.NET application.

Does SignalR use JSON?

ASP.NET Core SignalR supports two protocols for encoding messages: JSON and MessagePack. Each protocol has serialization configuration options.


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);
}
like image 154
TanvirArjel Avatar answered Oct 06 '22 06:10

TanvirArjel