SignalR Core 3.0 | Entity Framework | IHubContext | Hub methods

In this article, we are talking about @aspnet/signalr .net core version of the SignalR library. It is also called core signalr.

Method Should Be In camelCase with Proper Types

  • Like previous versions of the SignalR library or SignalR core, you can specify hub methods in whatever case you want
  • But when you’re invoking them from client side, you’ll have to use camelCase.
  • Make sure you’re using correct parameter types.
  • If you have specified an integer parameter on a method, then you must provide an int from client side. Passing an integer as string will raise exceptions.

HubContext is shortly lived so inject IHubContext as dependency

  • HubContext is shortly lived instance. So you must inject it as a dependency in constructor and save it in a variable in Hub.
  • You can call any method on that IHubContext type variable.
public class NotificationHub : Hub
    IHubContext<NotificationHub> _hubContext;

    public NotificationHub(IHubContext<NotificationHub> hubContext)
        _hubContext = hubContext;

Working Entity Framework and SignalR Core

EF Core Context will not stay active for longer so make a ContextFactory class to have a new context everytime you need it.

SignalR Core with WebRTC

  • Signalr works well as WebRTC communication relay.
  • You can specify a method on SignalR Hub and give it a parameter of Object type.
  • You can invoke that method from client side to send your candidates to the other WebRTC client and vice-versa.

Leave a Reply

Your email address will not be published. Required fields are marked *