Determining when to use Dependency Injection
Looking at a lot of MVC source code, I notice that most MVC projects (especially larger projects) implement dependency injection in one way or another.
I have two questions. First of all, is it feasible to create a large project without using dependency injection? I understand dependency injection makes large projects a lot easier to maintain and unit test. But how much more complex would a project be that didn't use dependency injection?
Second, when scoping the requirements of a new project, what criteria should I use to determine if I should use dependency injection? It requires a lot of initial setup and sometimes it seems unnecessary for a quick simple program.
There is no such thing like wrong or useless dependency injection so i recommend to use it always :)
It makes your code much more extensible, easier to test and also more readable (because the dependencies are clearly visible).
Second, when scoping the requirements of a new project, what criteria should I use to determine if I should use dependency injection?
it feasible to create a large project without using dependency injection?
It requires a lot of initial setup and sometimes it seems unnecessary for a quick simple program.
上一篇: Google Guice与PicoContainer进行依赖注入
下一篇: 确定何时使用依赖注入