Passing strongly typed Hubs in SignalR

前端 未结 4 1560
夕颜
夕颜 2021-02-05 15:59

I\'ve just updated some SignalR references and things have changed somewhat in order to allow for generically typed Hubs Hub. In the existing examples and

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-05 16:47

    There is now a new overload of GetHubContext that takes two generic parameters. The first is the Hub type like before, but the second generic parameter is TClient (which is the T in Hub).

    Assuming that StockTickerHub is defined as follows:

    public class TypedDemoHub : Hub
    

    Then

    GlobalHost.ConnectionManager.GetHubContext().Clients
    

    becomes

    GlobalHost.ConnectionManager.GetHubContext().Clients
    

    The type returned by the new overload to GetHubContext would be IHubContext and the Clients property would be IHubConnectionContext instead of IHubConnectionContext or IHubConnectionContext.

提交回复
热议问题