Graham
Graham

Reputation: 295

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?

Upvotes: 3

Views: 770

Answers (1)

Krzysztof Kozmic
Krzysztof Kozmic

Reputation: 27374

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).

Upvotes: 3

Related Questions