How to avoid Dependency Injection constructor madness?

前端 未结 9 1825
别跟我提以往
别跟我提以往 2020-11-22 03:59

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

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

with ever

9条回答
  •  孤独总比滥情好
    2020-11-22 04:36

    The difficulty of passing in the parameters is not the problem. The problem is that your class is doing too much, and should be broken down more.

    Dependency Injection can act as an early warning for classes getting too big, specifically because of the increasing pain of passing in all of the dependencies.

提交回复
热议问题