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?

  • You can avoid it for prototyping or if you are building something which will be not used in production environment.
  • it feasible to create a large project without using dependency injection?

  • yes but i do not recommend to do this
  • It requires a lot of initial setup and sometimes it seems unnecessary for a quick simple program.

  • Asp.MVC has good built in support for dependency injection. You can setup it pretty quickly. It is only matter of a nuget package instalation.
  • 链接地址: http://www.djcxy.com/p/82268.html

    上一篇: Google Guice与PicoContainer进行依赖注入

    下一篇: 确定何时使用依赖注入