StructureMap has the ability to apply conventions when scanning. Thus IFoo => Foo, without explicit registration.
Is something simular available in AutoFac? Looked around and just can't find anything helpfull.
Thanks,
The new scanning features in Autofac2 will imo remove some of the need for registration-by-convention. Lets say that Foo
lives in Plugins.dll:
var assembly = Assembly.Load("Plugins");
builder.RegisterAssemblyTypes(assembly)
.AsImplementedInterfaces();
This registration will pick up Foo
and register it as IFoo
.
You can use the ContainerBuilder.RegisterTypesMatching. Here's an example:
var builder = new ContainerBuilder();
builder.RegisterTypesMatching(type => type.IsAssignableFrom(typeof(IFoo)));
var container = builder.Build();
var foo = container.Resolve<Foo>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With