Let me first describe the situation
I have a component that uses dependency injection through a service locator. In the first scenario (image 1) the component needs a class that implements Interface0
, so it just asks for it at the service locator, something like this (in pseudocode):
Inferface0 i0 = serviceLocator.get(Interface0);
This first scenario is very simple. Now the second scenario, where the component and service locator stays the same, but now the component needs a class that implements Interface1
and Interface2
, like image 2 shows.
The question is, there is needed to create a new interface (let's call it Interface4
) that implements Interface1
and Interface2
so I can ask for it like following?
Inferface4 i4 = serviceLocator.get(Interface4);
And then, if later the component needs an implementation of Interface2
and Interface3
then a creation of Interface5
would be needed? What is the best approach to handle this interfaces?
Interface1
and anInterface2
dependency? What are you trying to achieve by stacking this into a singleInterface4
request from the service locator? It's not like you're being charged per request, are you?