Dependency injection (DI)

Dependency injection is one of several ways to implement IOC.

When classes collaborate with each other-or, more precisely, when we use composition between two classes (when class B is the property of class A)-we say that we have strongly coupled objects, which is a bad practice in object-oriented programming. Class A is too dependent on class B and could be badly affected by modifications to class B.

To avoid this strong dependency, we could use an abstraction of class B. We could use an interface, called IB, to replace class B as a property and then delegate the resolution of the interface IB with this concrete class to a tier component, a DI container, for example.

You do not have to use a DI container to do that, ...

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.