Calling SignalR hub clients from elsewhere in system

后端 未结 5 1013
情书的邮戳
情书的邮戳 2020-12-07 12:06

I\'ve set up a SignalR hub to communicate between the server and client. The hub server side code is stored in a class called Hooking.cs. What I want is to be able to call a

5条回答
  •  感情败类
    2020-12-07 12:43

    You can easily use a hub by following this 2 step-

    1. Instantiating by dependency injection like this-

      public class ClassName
      {
          ........
          ........
          private IHubContext _hub;
      
          public BulletinSenderController(IConnectionManager connectionManager)
          {
              _hub = connectionManager.GetHubContext();
              ........
              ........
          }
      
          ............
          ............
      }
      

    2.Using the hub object like this-

    _hub.Clients.All.onBulletinSent(bulletinToSend);
    

    More can be found here.

    Example code can be found in this git repo.

提交回复
热议问题