NServiceBus-容器

时间:2022-07-08 20:39:17

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
    {