I’ve only just started using Castle Windsor recently and have a question.
Suppose I have an interface- IService – and I have five classes that implement it (IServiceOne, IServiceTwo, IServiceThree) and so on.
From there I have classes that implmenent each of the IServices. They are appropriately named as ServiceOneProvider, ServiceTwoProvider, ServiceThreeProvider etc. Within these classes I am resolving an IService object.
So what I want to know is – Is it possible to have that IService object resolved using the equivalent of DefaultInterfaces (which can be used during registration) such that ServiceOneProvider will get a ServiceOne object, a ServiceTwoProvider will get a ServiceTwo object and so on?
Thanks,
-Ross
I didn’t see anything built in to Windsor to do something like that. I though about a HandlerSelector, but when the selector is running, you don’t know the type that is requesting the dependency so that wouldn’t help.
You could use the TypedFactoryFacility. Just create an interface to return your IService objects (C# version):
Then name your IService instances as “ServiceOne”, “ServiceTwo”, etc…
Then make your providers dependent on the factory and call the appropriate “Get” method: