This is a very simple question. I am using a IoC Container to register key depedencies at root level. For the rest of the dependencies, I use constructor injection..
What are the best practices to resolve dependecies between services of the same level of the application?
I could use the IoC Container as service locator, but I agree with some interpretations of Service Locator as Anti-pattern (http://blog.ploeh.dk/2010/02/03/ServiceLocatorisanAnti-Pattern/) and I agree that IoC Container should be focused on modularity and composition roots.
Another alternative is to create an explicit version of the locator where I could explicitly define the dependencies, but now i would be violating the Open-Close principle, because I would need to change "IServices" (and all the implementations of this interface) for each new "ServiceX" interface that I create in the future.
public interface IServices
{
IServiceA ServiceA { get; }
IServiceB ServiceB { get; }
IServiceC ServiceC { get; }
}
Now I went out of ideas. Is there an alternative?! Between these two approaches, I think would stay with the explicit version of the dependencies, but I am looking forward to know if there is a design pattern that could fit better to this scenario.
EDIT
Sorry for not being clear. The second approach is a constructor injection too, just like the first. The difference is that instead of passing the IoC Container to the constructor of the implementation of IServiceA, I would pass "IServices", that is a interface that explictly defines the dependencies of "IServicesA".