Question

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?

Was it helpful?

Solution

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();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top