今天我从 1.0.0alpha2 升级到 Signalr 1.0.0,我注意到我必须更改我的Application_Start
.
前:
UnityContainer = Bootstrapper.Initialize();
var unityDependencyResolver = new UnityDependencyResolver(UnityContainer);
DependencyResolver.SetResolver(unityDependencyResolver);
var signalRUnityDependencyResolver = new SignalRUnityDependencyResolver(UnityContainer);
RouteTable.Routes.MapHubs(signalRUnityDependencyResolver);
GlobalHost.DependencyResolver = signalRUnityDependencyResolver;
AreaRegistration.RegisterAllAreas();
现在:
UnityContainer = Bootstrapper.Initialize();
var unityDependencyResolver = new UnityDependencyResolver(UnityContainer);
DependencyResolver.SetResolver(unityDependencyResolver);
var signalRUnityDependencyResolver = new SignalRUnityDependencyResolver(UnityContainer);
//RouteTable.Routes.MapHubs(signalRUnityDependencyResolver);
RouteTable.Routes.MapHubs();
GlobalHost.DependencyResolver = signalRUnityDependencyResolver;
AreaRegistration.RegisterAllAreas();
我知道RouteTable.Routes.MapHubs();
应该首先出现的文档状态,但这只会让一切都挂在那条线上。这是我发现实际加载的唯一方法。
但是当我尝试进行数据库调用时,我没有得到异常或任何东西,但网站会冻结。当我在调试器中点击暂停时,它在遇到的第一个 EF5 查询中被冻结。但也不例外,所有属性都表示为:
Cannot evaluate expression because a native frame is on top of the call stack.
当我删除RouteTable.Routes.MapHubs();
一切再次工作(除了Signalr)。
有时它甚至没有走那么远,然后它就挂了AreaRegistration.RegisterAllAreas();
。
Signalr 的每次更新都会再次发生变化,现在让我发疯了。
让 Unity+Signalr 工作的正确调用顺序应该是什么?
编辑: 经过一番摆弄后,当我禁用以下几行时,它似乎可以工作:
var signalRUnityDependencyResolver = new SignalRUnityDependencyResolver(UnityContainer);
GlobalHost.DependencyResolver = signalRUnityDependencyResolver;