本文介绍了与ASP.NET MVC4和StructureMap配置NServiceBus的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我从安装的NuGet和structuremap创建structuremap.mvc4一个ASP.NET MVC 4 Web应用程序。然后,我添加了nservicebus和nservicebus.structuremap包,也从的NuGet。

I created an ASP.NET MVC 4 web application by installing structuremap and structuremap.mvc4 from nuget. I then added the nservicebus and nservicebus.structuremap packages, also from from nuget.

我已经创建了structuremap一对夫妇mvc4应用之前,没有任何问题,我已经遵循基本的pub / sub与nservicebus和structuremap一些教程,并得到它的工作。

I've created a couple mvc4 apps with structuremap before with no problems, and I've followed a few tutorials for basic pub/sub with nservicebus and structuremap and got it to work.

不过,把nservicebus到mvc4与structuremap不,当我试图很好地工作。
我遇到的问题是,对于MVC和DI下面MVC列出的nservice总线教程似乎想要开发者使用内置的依赖注入容器。

However, putting nservicebus into mvc4 with structuremap doesn't work very well when I tried.The problem I'm encountering is that the nservice bus tutorials for mvc and DI with MVC listed below seem to want the developers to use the built in Dependency Injection container.

结果

如果您以前使用过的结构图,该包装的NuGet很好地增加了解析器和运行使用WebActivator初始设置。在那之后,我不知道会发生什么容器,所以我不能用它来设置NServiceBus生成器在Configure.With()。StructureMapBuilder(StructureMap集装箱)。

If you've used structure map before, the nuget package nicely adds the resolver and runs initial setup using WebActivator. After that, I'm not sure what happens to the container, so I can't use it to set the NServiceBus Builder in Configure.With().StructureMapBuilder(StructureMap Container).

我有什么才能使nservicebus做,structuremap在asp.net MVC4发挥好?我知道它的操作错误,但我不知道在这一点上做的?另外,没有第3版有messageendpointconfig的地方用一些漂亮的配置的角色?这是否不是在网络环境中应用?我想我可以只得到一个裁判的容器去,但是这似乎并不如此。

What do I have to do in order to make nservicebus and structuremap play nice in asp.net MVC4? I know its operator error, but I'm not sure what to do at this point? Also, doesn't version 3 have a messageendpointconfig somewhere with some nifty configuration roles? Does that not apply in a web environment? I figured I could just get a ref to the container and go, but that doesn't seem to be the case.

编辑:添加了一些code

added some code

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.RegisterAuth();

        Configure.With()
            .StructureMapBuilder(ObjectFactory.Container) //this obviously won't work
            .JsonSerializer()
            .Log4Net()
            .MsmqTransport()
                .IsTransactional(false)
                .PurgeOnStartup(true)
            .UnicastBus()
                .ImpersonateSender(false)
            .CreateBus()
            .Start(() => Configure.Instance.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install());

    }

编辑2:
即使我得到过去的问题与StructureMap移动在这里我设置的依赖解析器的Application_Start(),NServiceBus仍然要为MessageForwardingInCaseOfFaultConfig和MsmqTransportConfig配置。

EDIT 2:Even if I get past the issue with StructureMap by moving where I set the dependency resolver to Application_Start(), NServiceBus still wants configuration for MessageForwardingInCaseOfFaultConfig and MsmqTransportConfig.

我想,我记得这些属性都应该通过接口在端点上的配置?

I think I remember that those properties are supposed to be automatically configured by the roles set through the interfaces on the endpoint config?

推荐答案

您需要将这些部分添加到您的web.config文件:

You need to add these sections to your web.config file:

<configuration>
  <configSections>
    <section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/>
  </configSections>

  <MessageForwardingInCaseOfFaultConfig ErrorQueue="error"/>
  <MsmqTransportConfig NumberOfWorkerThreads="1" MaxRetries="5"/>
</configuration>

NServiceBus V3不会自动创建这些!

NServiceBus v3 does not create these automatically!

这篇关于与ASP.NET MVC4和StructureMap配置NServiceBus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 19:58