I\'m using Autofac and would like to have multiple implementations of an interface. How can I configure Autofac so to resolve dependencies based on the current type?
Mor
Not too difficult. You can register concrete types as self and resolve it as you go along. Then your top level message handler (LoggingMessageHandler in your example) can be registered for the interface, which will be used by your TopLevelClass
Here's what you're looking at (assuming you have a default constructor for FinalHandler)
var builder = new ContainerBuilder();
builder.RegisterType().AsSelf().SingleInstance();
builder.Register(c => new DoSomethingMessageHandler(c.Resolve())).AsSelf().SingleInstance();
builder.Register(c => new LoggingMessageHandler(c.Resolve())).As().SingleInstance();
//now finally your top level class - this will automatically pick your LoggingMessageHandler since the others have been registered onto their concreteTypes only
builder.RegisterType().As().InstancePerOwned();