Documente Academic
Documente Profesional
Documente Cultură
Net
Mvc
Introduction
Dependency injection is a programming and application design pattern which is being used by
developers for so many years now. This pattern comes as a default programming syntax in many
frameworks like Angular and we must follow them in order to use the framework. I will not go
much into explaining what Dependency Injection actually is because there is much information
available on the subject which could be accessed using a simple web search. Here is the formal
definition from Wikipedia:
Quote:
In software engineering, dependency injection is a software design pattern that
implements inversion of control for resolving dependencies. A dependency is an object
that can be used (a service). An injection is the passing of a dependency to a dependent
object (a client) that would use it.
Dependency Injection promotes loose coupling between application modules and provides us means
to switch code modules being used without building and redeploying the entire application or parts
of it. This could be done by using either application configuration file or by reading dependency
information from a database table.
We can create a DI code framework of our own for custom scenarios. But in Asp.Net Mvc in order
to use DI in certain areas we must follow the .Net approach. This could be done by implementing
in-built interfaces into classes and wiring them up from Global.asax when the application starts.
I am assuming that you are aware of dependency injection as a design pattern and as a programming
concept before you start reading further. In this article I will be giving examples of DI in different
areas of Asp.Net Mvc application architecture. There will be partial code demonstration in this
article and the entire example could be downloaded from either here or from GitHub where I have
uploaded it in a public repository.