Cannot pass a DependencyResolver to MapSignalR in a HubConfiguration

六眼飞鱼酱① 提交于 2019-12-06 02:42:40
halter73

I think Lars Höppner (the user who left the first comment on this post) is right.

You can definitely use a custom dependency resolver without changing GlobalHost.DependencyResolver (the SignalR test suite does this quite often), but you have to be sure GlobalHost doesn't show up anywhere else in your code.

This means that absolutely no references to:

  • GlobalHost.Configuration
  • GlobalHost.ConnectionManager
  • GlobalHost.TraceManager
  • GlobalHost.HubPipeline
  • and of course GlobalHost.DependencyResolver

The SO post Lars linked to (SignalR: Sending data using GlobalHost.ConnectionManager not working) shows you how to get the ConnectionManager from your custom dependency resolver; you can do the same thing for all the other properties on GlobalHost.

I'm assuming you're performing the second approach yet still trying to use the GlobalHost dependency resolver.

If you wire your custom dependency resolver up via your second approach the GlobalHost's dependency resolver will not be the same as the one you pass into your custom hub configuration.

Therefore in order to still use the GlobalHost object you'll need to do your second approach AND set the GlobalHost dependency resolver:

var resolver = new CustomSignalRDependencyResolver(...);
app.MapSignalR(new HubConfiguration(
{
    Resolver = resolver
});
GlobalHost.DependencyResolver = resolver;

Hope this helps!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!