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.
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.
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.
ASP.NET Core SignalR supports two protocols for encoding messages: JSON and MessagePack. Each protocol has serialization configuration options.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With