你如何解决signalR V2.0与StructureMap V2.6

编程入门 行业动态 更新时间:2024-10-26 06:32:07
本文介绍了你如何解决signalR V2.0与StructureMap V2.6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在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

本文发布于:2023-11-16 15:09:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605394.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何解决   signalR   StructureMap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!