Calling SignalR hub clients from elsewhere in system

后端 未结 5 994
情书的邮戳
情书的邮戳 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:54

    This has changed in .NET Core 2, now you can use dependency injection like this:

        private readonly IHubContext _hubContext;
    
        public MyController(MyHub,IMyHubInterface hubContext)
        {
            _hubContext = hubContext;
        }
    
        public bool SendViaSignalR()
        {
            _hubContext.Clients.All.MyClientSideSignalRMethod(new MyModel());
            return true;
        }
    

提交回复
热议问题