MassTransit和Simple Injector

时间:2013-01-08 18:23:42

标签: c# inversion-of-control 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,但我无法找到一个集成库,将简单注入器添加到MassTransit。

有没有人试过这个,让它工作并有一些代码可以让我开始?

1 个答案:

答案 0 :(得分:6)

我对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();
}