在Global.asax中的的Application_Start我有以下
In Application_Start of Global.asax i have the following
ObjectFactory.Initialize(cfg => { cfg.For<IDependencyResolver>().Singleton().Add<StructureMapDependencyResolver> (); });我对集线器接口
public interface IDashboardHub { void Initialize(); }和我的枢纽如下:
public class DashboardHub : Hub, IDashboardHub { private readonly ICpeAccountService _accountService; public DashboardHub(ICpeAccountService service) { _accountService = service; } [Authorize] public void Initialize() { Clients.All.UpdateStatus("Hello World!!!"); } }如果我删除注入的构造函数和解析器然后我得到的Hello World的信号和JavaScript显示值。如果我只是删除解析器然后signalR不再发现一个参数的构造函数和初始化方法不会被调用。
If I remove the injected constructor and the Resolver then I get the "Hello World" signal and the JavaScript display the value. If I just remove the resolver then signalR no longer finds a parameterless constructor and the Initialize methods does not get called.
如果我包括StructureMap依赖解析器(这是工作,现在注入约40其他类),然后我得到下面的异常信息
If I include the StructureMap dependency resolver (which is working and injecting around 40 other classes right now) then i get the following exception message
StructureMap configuration failures: Error: 104 Source: Registry: StructureMap.Configuration.DSL.Registry, StructureMap, Version=2.6.4.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223 Type Instance '87da3c00-4deb-4334-b189-021d445d95ec' (Configured Instance of App.DependencyResolution.StructureMapDependencyResolver, App, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) Cannot be plugged into type Microsoft.AspNet.SignalR.IDependencyResolver, Microsoft.AspNet.SignalR.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35另外,如果我尝试只是解决这一切startup.cs,像这样的:
Also if I try to just resolve this all in startup.cs, like this:
public void Configuration(IAppBuilder app) { ObjectFactory.Initialize(cfg => { cfg.For<IDependencyResolver>() .Singleton() .Add<StructureMapDependencyResolver>(); }); app.MapSignalR(); }我也得到了同样的错误。
I also get the same error.
有没有人能解决这个问题?
Has anyone been able to resolve this issue?
推荐答案最简单的方法是使用HubActivator
The easiest way is to use a HubActivator
所有你需要的启动,CS是
All you need in startup,cs is
public void Configuration(IAppBuilder app) { app.MapSignalR(); }您的集线器建立一个激活
Create a Activator for your hubs
public class HubActivator : IHubActivator { private readonly IContainer container; public HubActivator(IContainer container) { this.container = container; } public IHub Create(HubDescriptor descriptor) { return (IHub)container.GetInstance(descriptor.HubType); } }请确保您在app_start注册该激活
Make sure that you register this activator in app_start
IContainer container = StructureMap.Container(); // Register a Hub Activator for SignalR GlobalHost.DependencyResolver.Register(typeof(IHubActivator), () => new HubActivator(container));然后删除任何SignalRDependencyResolver code作为其不需要......
and then remove any SignalRDependencyResolver code as its not needed...
更多推荐
你如何解决signalR V2.0与StructureMap V2.6
发布评论