Determining the use of dependency injection

Looking at a lot of MVC source code, I notice that most MVC projects (especially large projects) implement dependency injection in one way or another.

I have two questions. First, is it possible to create a large project without using dependency injection? I understand that dependency injection makes large projects much easier to maintain and unit test. But how much more complex would a project be that didn't use dependency injection?

Second, when defining the requirements of a new project, what criteria should I use to determine if I should use dependency injection? This requires a lot of initial setup and sometimes seems unnecessary for a quick, simple program.

+3


source to share


1 answer


There is no such thing as wrong or useless dependency injection, so I recommend using it always :)

This makes your code much more extensible, easier to test, and also more readable (because the dependencies are clearly visible).

Second, when defining the requirements of a new project, what criteria should be used to determine if dependency injection should be used?

  • You can avoid this for prototyping or if you are doing something that will not be used in a production environment.


is it possible to create a large project without using dependency injection?

  • yes, but I do not recommend doing this

This requires a lot of initial setup and sometimes seems unnecessary for a quick, simple program.

  • Asp.MVC has good built-in support for dependency injection. You can set it up pretty quickly. It's just a matter of installing the nuget package .
+1


source







All Articles