Integration with Autofac is simple, there are extension methods in MassTransit.Autofac .
First, there is an AutofacConsumerFactory that will allow your consumers out of the container. You can add this to the container, or you can register it yourself using:
builder.RegisterGeneric(typeof(AutofacConsumerFactory<>)) .WithParameter(new NamedParameter("name", "message")) .As(typeof(IConsumerFactory<>));
Then in the builder statement for the endpoint of the bus and the receiver:
e.Consumer(() => context.Resolve<IConsumerFactory<TakeMeasureConsumer>());
Then you allow your consumers from the container.
Update:
For newer versions of MassTransit, add receive endpoints as follows:
e.Consumer<TakeMeasureConsumer>(context);
source share