MassTransit and Simple Injector [closed]

你说的曾经没有我的故事 提交于 2019-12-06 05:30:01

问题


I'm reviewing the MassTransit Distributed Application Framework for .NET. According to the website MassTransit has been built from the beginning with the concept of an IoC container being involved and provides support libraries for a handful of the more "mainstream" IoC Containers. There are (currently) NuGet packages available for Autofac, StructureMap, Castle Windsor, Ninject & Unity.

I have selected Simple Injector as my IoC container of choice for performance reasons but I am unable to find an integration library adding support for Simple Injector to MassTransit.

Has anyone tried this, got it to work and have some code available to get me started?


回答1:


I'm not familiar with MassTransit, but after looking at the configuration examples for the other containers, this is what I came up with:

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


来源:https://stackoverflow.com/questions/14221571/masstransit-and-simple-injector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!