Most of my IoC experience has been using StructureMap, with the default conventions:
container.Configure(c => c.Scan(s =>
{
s.Assembly(GetType().Assembly);
s.LookForRegistries();
s.WithDefaultConventions();
}));
Which registers any components whose name matches the interface, minus the I, e.g. ThingyController : IThingyController, but not DefaultThingyRepository : IThingyRepository.
Recently however, I’ve worked on a few projects using Castle Windsor, whose auto-registration uses the first interface:
container.Register(AllTypes
.FromAssembly(GetType().Assembly)
.Pick()
.WithService.FirstInterface()
.Configure(req => req.LifeStyle.Transient));
What a great idea, I thought! Why can’t I do that with StructureMap? Well the short answer is, you can:
container.Configure(c => c.Scan(s =>
{
s.Assembly(GetType().Assembly);
s.LookForRegistries();
s.RegisterConcreteTypesAgainstTheFirstInterface();
}));
Hurray!