Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contextual Binding with Castle Windsor

Is it possible to get Windsor to return different implementations of a service based on a seperate parameter?

For example, if I have a User object which has a Role property, I would like to be able to hydrate this object differently according the the value of Role. I would like to use an IUserService to do this, but have the concrete implementation of IUserService determined by the IoC container.

I think that Ninject offers this functionality as "Contextual Binding" but I'm not sure if Windsor offers it without rolling my own resolution logic?

like image 786
Graham Avatar asked Feb 05 '26 14:02

Graham


1 Answers

No, it is not possible (yet). Take a look here and here. For now take a look at HandlerProvider if it's got what you need. If not, you may need to use ISubDependencyResolver (which is not very complicated actually).

like image 99
Krzysztof Kozmic Avatar answered Feb 09 '26 09:02

Krzysztof Kozmic