0 votes
1 view
ago in Java by (2.1k points)

I find that my constructors are starting to look like this:

public MyClass(Container con, SomeClass1 obj1, SomeClass2, obj2.... )

with ever-increasing parameter list. Since "Container" is my dependency injection container, why can't I just do this:

public MyClass(Container con)

for every class? What are the downsides? If I do this, it feels like I'm using a glorified static. Please share your thoughts on IoC and Dependency Injection madness.

1 Answer

0 votes
ago by (21.7k points)

You are correct that if you apply the container as a Service Locator, it's larger or less an acclaimed static layout. For many purposes, I examine this as an anti-pattern.

One of the amazing gains of Constructor Injection is that it gives breaches of the Single Responsibility Principleglaringly public.

When that occurs, it's time to refactor to Facade Services. In summary, design a new, more coarse-grained interface that covers the synergy between some or all of the fine-grained provinces you currently need.