0

全部。我开始使用NServiceBus,并且基于Pluralsight和因特网的基础知识掌握了相当好的技术。我有一个股票MVC 4项目,我已经为我的控制器设置了依赖注入(感谢this blog post)。NServiceBus/MVC注入 - Autofac不喜欢IControllerFactory?

这里是我在我的Global.asax总线设置:

_bus = Configure.With() 
       .DefaultBuilder() 
       .ForMVC() 
       .Log4Net() 
       .XmlSerializer() 
       .MsmqTransport() 
       .UnicastBus() 
       .SendOnly(); 

我将其分配给本地私有变量,因为我需要访问全球总线,所以我可以做Session_End中的一些东西。然而,当我跑,我得到以下错误:

The requested service 'System.Web.Mvc.IControllerFactory' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.

根据我的堆栈跟踪信息,故障点是当Autofac尝试解析式。为了理智,我删除了私有变量,只使用了配置语句,同样的事情。我也有Ninject在这个应用程序连线,因为这是我的首选IoC。考虑到它以某种方式干扰Autofac,我将Ninject从等式中删除,但仍然无法工作。

所以我的问题是,我做错了什么?我错过了什么吗?这是我第一次与NServiceBus,但从我见过的一切,这应该只是工作。任何信息会超级有用。谢谢。

回答

0

我发现从你的代码,约翰的解决方案!这是我的问题。这是我在我的依赖解析器适配器:

public object GetService(Type serviceType) 
{ 
    _builder.Build(serviceType); 
} 

我需要做什么是你在你的MVC4例如做了什么:

public object GetService(Type serviceType) 
{ 
    return (Configure.Instance.Configurer.HasComponent(serviceType)) ? _builder.Build(serviceType) : null; 
} 

一旦我做到了,这一切都整理自己了。再次感谢您的帮助!