Created
November 8, 2011 13:53
-
-
Save CraigStuntz/1347782 to your computer and use it in GitHub Desktop.
Possible means of using Autofac with MassTransit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) |
One could also use Assembly.GetExecutingAssembly
.
Ok, that's what I want. Thanks. Its now in the docs. :)
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
"Find every type in the assembly which contains SomeClass that happens to support the IConsumer interface and register it with the container such that when we are later ask for IConsumer implementations, we'll get those types."
The thing which is confusing, at first glance, is
typeof(SomeClass).Assembly
. Autofac doesn't have.FromThisAssembly()
like Windsor (as far as I know), so you just need an assembly reference for the relevant assembly. Pick any class in that assembly, and use theType.Assembly
property to get that reference.