Skip to content

Instantly share code, notes, and snippets.

@CraigStuntz
Created November 8, 2011 13:53
Show Gist options
  • Save CraigStuntz/1347782 to your computer and use it in GitHub Desktop.
Save CraigStuntz/1347782 to your computer and use it in GitHub Desktop.
Possible means of using Autofac with MassTransit
public static void main(string[] args)
{
var builder = new ContainerBuilder();
// register each consumer manually
builder.RegisterType<YourConsumer>().As<IConsumer>();
//or use Autofac's scanning capabilities -- SomeClass is any class in the correct assembly
builder.RegisterAssemblyTypes(typeof(SomeClass).Assembly).As<IConsumer>();
//now we add the bus
builder.Register(c => ServiceBusFactory.New(sbc =>
{
//other configuration options
//this will find all of the consumers in the container and
//register them with the bus.
sbc.LoadFrom(c);
})).As<IServiceBus>()
.SingleInstance();
var container = builder.Build();
}
// Note: We recommend that most of this code be placed in an Autofac Module
// ( http://code.google.com/p/autofac/wiki/StructuringWithModules )
@drusellers
Copy link

Yeah, but that's less explicit for most users. Keep it concrete, keep it clear. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment