Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (2.6k 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
by (46k 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.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 15, 2019 in Java by Nigam (4k points)

Browse Categories

...