码迷,mamicode.com
首页 > 其他好文 > 详细

NServiceBus-容器

时间:2015-02-16 18:19:10      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

NServiceBus自动注册以及用户实现其所有组件处理程序和传奇,这样所有实例化模式和连接在默认情况下都是正确的,没有错误。

NServiceBus在容器构建(目前Autofac的ilmerge版本),但它可以取代任何其他容器。

获得其他容器

nuget其他容器可用。

配置NServiceBus使用其他容器

  • v5
  • V4

    编辑

    var configuration = new BusConfiguration();
    
    // Autofac
    configuration.UseContainer<AutofacBuilder>();
    // Autofac with a container instance
    configuration.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(lifetimeScope));
    
    // Castle
    configuration.UseContainer<WindsorBuilder>();
    // Castle with a container instance
    configuration.UseContainer<WindsorBuilder>(c => c.ExistingContainer(windsorContainer));
    
    // Ninject
    configuration.UseContainer<NinjectBuilder>();
    // Ninject with a container instance 
    configuration.UseContainer<NinjectBuilder>(c => c.ExistingKernel(ninjectKernel));
    
    // Unity
    configuration.UseContainer<UnityBuilder>();
    // Unity with a container instance 
    configuration.UseContainer<UnityBuilder>(c => c.UseExistingContainer(unityContainer));
    
    // Spring
    configuration.UseContainer<SpringBuilder>();
    // Spring with an instance 
    configuration.UseContainer<SpringBuilder>(c => c.ExistingApplicationContext(springApplicationContext));
    
    // StructureMap
    configuration.UseContainer<StructureMapBuilder>();
    // StructureMap with a container instance 
    configuration.UseContainer<StructureMapBuilder>(c => c.ExistingContainer(structureMapContainer));
    

    插入自己的容器

    • v5
    • V4

      编辑

      public void CustomContainerExtensionUsage()
      {
          var configuration = new BusConfiguration();
          //Register the container in the configuration with ‘.UseContainer<T>()‘
          configuration.UseContainer<MyContainer>();
      }
      // Create a class that implements ‘ContainerDefinition‘ and returns your ‘IContainer‘ implementation.
      public class MyContainer : ContainerDefinition
      {
          public override IContainer CreateContainer(ReadOnlySettings settings)
          {
              return new MyObjectBuilder();
          }
      }
      //Create a class that implements ‘IContainer‘
      public class MyObjectBuilder : IContainer
      {
    • NServiceBus-容器

      标签:

      原文地址:http://www.cnblogs.com/powerxu/p/4294306.html

      (0)
      (0)
         
      举报
      评论 一句话评论(0
      登录后才能评论!
      © 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
      迷上了代码!