SignalR: Sending data using GlobalHost.ConnectionManager not working

后端 未结 1 1426
独厮守ぢ
独厮守ぢ 2020-12-03 14:49

I have a hub like this:

public class MessageHubBub : Hub
{

    public void ServerMethod()
    {
        Clients.All.sayHi(\"hello\");
        GlobalHost.Con         


        
相关标签:
1条回答
  • 2020-12-03 15:20

    When using a custom dependency resolver, it is not enough to pass it to the HubConfiguration.

    You need to either store the resolver instance somewhere and use it like this to access the connection manager and your hub context:

    MyDependencyResolver.Resolve<IConnectionManager>().GetHubContext<MyHub>();
    

    or set the default dependency resolver in GlobalHost to your instance:

    var myResolver = new SignalRUnityDependencyResolver(unityContainer);
    RouteTable.Routes.MapHubs( new HubConfiguration() { Resolver = myResolver } );
    GlobalHost.DependencyResolver = myResolver;
    

    (then you can use the default GlobalHost.ConnectionManager.GetHubContext<MessageHubBub>())

    0 讨论(0)
提交回复
热议问题