Ninject (WhenInjectedInto) function equivalent in Windsor

This is my first post here, hoping to start publishing again in the future :)

I'm trying to learn how to use Castle Windsor and not use Ninject, but there’s one feature that I couldn’t sort of “translate” for use in Windsor, which is WhenInjectedInto.

Here is one example taken from Pro ASP.NET MVC 5, with Ninject

kernel.Bind<IValueCalculator>().To<LinqValueCalculator>();
kernel.Bind<IDiscountHelper>().To<FlexibleDiscountHelper>().WhenInjectedInto<LinqValueCalculator>();

This is a conditional binding, meaning that when a LinqValueCalculator is bound to an IValueCalculator, it should use the FlexibleDiscountHelper when binding to the IDiscountHelper, and not to any other object.

How can I reproduce this using Windsor, if possible?

So far, I:

container.Register(Component.For<IValueCalculator>().ImplementedBy<LinqValueCalculator>());
container.Register(Component.For<IDiscountHelper>().ImplementedBy<FlexibleDiscountHelper>());

Thanks in advance, Bruno

+4
2

DependsOn:

container.Register(
    Component.For<IDiscountHelper>()
             .ImplementedBy<FlexibleDiscountHelper>());

container.Register(
    Component.For<IValueCalculator>()
             .ImplementedBy<LinqValueCalculator>()
             .DependsOn(Dependency.OnComponent<IDiscountHelper, FlexibleDiscountHelper>());

, , , .

+4

, .

Ninject When , , IHandlerSelector, , IHandlerSelector HasOpinionAbout.

Ayende , HandlerSelectors .

+1

All Articles