When can Dependency Injection Containers become too big, and what can I do about it?

后端 未结 3 596
再見小時候
再見小時候 2021-02-05 17:09

We all know the why Dependency Injection is awesome because it makes code less coupled, easier to test, and much nicer to read! And then some decide to use a

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 18:08

    Well, there are a few things to consider when thinking about answering this question. But the primary one (which I think should answer your point):

    Do You Really Use All 1000 Classes As Dependencies?

    Quite often, we have large applications, but the typical portions of it that are used as dependencies are actually typically quite a lot smaller. The reason is that a large number of classes tend to be domain objects. Objects that represent data or business cases in the application. Those classes are almost never dependencies, but are created using factories, mappers and the like.

    Additionally, things like Views and other functionality-specific classes and code will likely not be managed by the DIC.

    So you'll have a large portion of code that doesn't need to be managed by the container.

提交回复
热议问题