This is my first post here, hoping to start also posting more often in the future :)
I have been trying to learn to use Castle Windsor rather than using Ninject but there's one feature I haven't been able to sort of "translate" to use in Windsor, and that is WhenInjectedInto.
Here's one example taken from Pro ASP.NET MVC 5 book, with Ninject
kernel.Bind<IValueCalculator>().To<LinqValueCalculator>();
kernel.Bind<IDiscountHelper>().To<FlexibleDiscountHelper>().WhenInjectedInto<LinqValueCalculator>();
This is a conditional binding, meaing that when it's LinqValueCalculator that is being bound to IValueCalculator, it should use FlexibleDiscountHelper when binding to IDiscountHelper, rather than any other object.
How can I replicate this with Windsor, if it's even possible ?
So far I have:
container.Register(Component.For<IValueCalculator>().ImplementedBy<LinqValueCalculator>());
container.Register(Component.For<IDiscountHelper>().ImplementedBy<FlexibleDiscountHelper>());
Thanks in advance, Bruno
I would just use
DependsOn
:There are a number of different ways to specify this dependency, check out the documentation if this specification isn't exactly what you need.