标签:
NServiceBus自动注册以及用户实现其所有组件处理程序和传奇,这样所有实例化模式和连接在默认情况下都是正确的,没有错误。
NServiceBus在容器构建(目前Autofac的ilmerge版本),但它可以取代任何其他容器。
nuget其他容器可用。
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));
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
{
标签:
原文地址:http://www.cnblogs.com/powerxu/p/4294306.html