In Castle Windsor there is a feature called forwarded types where you can have one component configuration for multiple services. For example:
var container = new WindsorContainer();
container.Register(
Component.For<Bar>().Forward<IFoo>()
.ImplementedBy<FooBar>());
var foo = container.Resolve<IFoo>();
var bar = container.Resolve<Bar>();
Debug.Assert(foo == bar);
(this Debug.Assert works ’cause Windsor by default registers things as singletons)
How to achieve this in Ninject (version 2) ?
I’m interested to see if anyone else chimes in with a better solution, but here’s an option:
Use a special IProvider when binding to do the forward:
and then when binding:
and my test: