c# - Ninject feature (WhenInjectedInto) equivalent in Windsor -
c# - Ninject feature (WhenInjectedInto) equivalent in Windsor -
this first post here, hoping start posting more in future :)
i have been trying larn utilize castle windsor rather using ninject there's 1 feature haven't been able sort of "translate" utilize in windsor, , wheninjectedinto.
here's 1 illustration taken pro asp.net mvc 5 book, ninject
kernel.bind<ivaluecalculator>().to<linqvaluecalculator>(); kernel.bind<idiscounthelper>().to<flexiblediscounthelper>().wheninjectedinto<linqvaluecalculator>();
this conditional binding, meaing when it's linqvaluecalculator beingness bound ivaluecalculator, should utilize flexiblediscounthelper when binding idiscounthelper, rather other object.
how can replicate windsor, if it's possible ?
so far have:
container.register(component.for<ivaluecalculator>().implementedby<linqvaluecalculator>()); container.register(component.for<idiscounthelper>().implementedby<flexiblediscounthelper>());
thanks in advance, bruno
i utilize dependson
:
container.register( component.for<idiscounthelper>() .implementedby<flexiblediscounthelper>()); container.register( component.for<ivaluecalculator>() .implementedby<linqvaluecalculator>() .dependson(dependency.oncomponent<idiscounthelper, flexiblediscounthelper>());
there number of different ways specify dependency, check out the documentation if specification isn't need.
c# .net dependency-injection asp.net-mvc-5 castle-windsor
Comments
Post a Comment