-
Book Overview & Buying
-
Table Of Contents
An Atypical ASP.NET Core 5 Design Patterns Guide
By :
Dependency Injection (DI) is a way to apply the Inversion of Control (IoC) principle. We could see IoC as a broader version of the Dependency Inversion principle (the D in SOLID).
The idea behind DI is to move the creation of dependencies from the objects themselves to the entry point of the program (the composition root). That way, we can delegate the management of dependencies to an IoC container (also known as a DI container), which does the heavy lifting.
For example, object A should not know about object B that it is using. A should instead use an interface I implemented by B, and B should be resolved and injected at runtime.
Let's decompose this:
A should depend on interface I instead of concretion B.B, injected into A, should be resolved at runtime by the IoC container.A should not be aware of the existence of B.A should not control the lifetime of B.To go all out LEGO®, we could...