c# – MassTransit和Simple Injector
作者:互联网
我正在审查MassTransit Distributed Application Framework for .NET.根据网站MassTransit has been built from the beginning with the concept of an IoC container being involved,并为少数更“主流”的IoC容器提供支持库.有(目前)NuGet包可用于Autofac,StructureMap,Castle Windsor,Ninject&统一.
我选择了Simple Injector作为我选择的IoC容器for performance reasons,但是我无法找到一个集成库,它将对Simple Injector的支持添加到MassTransit.
有没有人试过这个,让它工作,有一些代码可以让我开始?
解决方法:
我不熟悉MassTransit,但看了the configuration examples for the other containers之后,这就是我提出的:
public static void main(string[] args)
{
var container = new Container();
var consumers = container.GetTypesToRegister(typeof(IConsumer),
applicationAssemblies);
foreach (Type consumer in consumers)
container.Register(consumer);
IServiceBus bus = ServiceBusFactory.New(sbc => {
//other configuration options
sbc.Subscribe(subs => {
foreach (var consumer in consumers)
subs.Consumer(consumer);
});
});
container.RegisterSingle<IServiceBus>(bus);
container.Verify();
}
标签:c,inversion-of-control,simple-injector,masstransit 来源: https://codeday.me/bug/20190529/1180089.html