From the course: ASP.NET Core in .NET 6: Dependency Injection
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
What is dependency injection? - ASP.NET Core Tutorial
From the course: ASP.NET Core in .NET 6: Dependency Injection
What is dependency injection?
- The Inversion of Control, or IoC design principle, is defined as given responsibility for control or logic to something else such as a framework. Dependency injection, or DI, is a design pattern that is part of the IoC design pattern allows dependent objects of a class to be created elsewhere rather than in the class itself. Take this example, a customer wishes to purchase a baseball bat from an online store. However, before they purchase it, they want to know how much they're paying for it. At this point, they aren't interested in the shipping costs. However, the weight of the product would have to be used to calculate shipping costs should they wish to purchase it. If the product service was dependent on the shipping cost service, it would have to create the shipping cost service when creating the product service even if the customer didn't want to buy it. However, with dependency injection, we can keep our product and…