From the course: Advanced ASP.NET Web API 2.2

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

What is dependency injection?

What is dependency injection?

From the course: Advanced ASP.NET Web API 2.2

Start my 1-month free trial

What is dependency injection?

- In software development, dependency injection is a technique where one object supplies the needs, or dependencies, of another object. Let's break this technical concept down into a real world example. Let's say we want to eat ice cream, but to eat ice cream it needs to be produced. Ice cream is dependent on two key components, milk and ice. So, the milk and ice are the dependencies for the ice cream. On the other hand, we need a container for these dependencies, so each time we need them we can just go and get them. The containers in this case would be the cow for the milk and the fridge for the ice. Now, this seems pretty obvious right? How can we understand it in programming? Well, let's think of a class which uses another service, or class, to get data. In this case, the service or the other class would be the dependencies, but the same way as with the milk and the ice, you need a place to store them so you can…

Contents