Review of old topic regarding dependency injection. Why it's still important and actual in the industry. Will look into more depth of this is handled in Episerver and related libraries.
12. @tech_fellow
«DI is a set of principles and patterns that enable loose
coupling* »
* - http://blog.ploeh.dk/2010/04/07/DependencyInjectionisLooseCoupling/
DI fuels SOLID
Dependency Inversion Principle (the D in SOLID) is the guiding principle behind DI.
Compose whole graph and get DI container out of way in layers below.
Read bottom-up = to understand dependency graph and required dependencies for other services.
Cannot replace dependencies after application has been compiled (in unit tests). Drags unnecessary dependencies.
Main problem – it uses FOREIGN DEFAULT
We lose flexibility. Fx does not know what exactly component will need for composition.
The essence here – is not how component is constructed, but how it’s used.
Refactor to Facasde Services, makes it easy to see and react on violation of SRP.
Frameworks are designed with Dependency Inversion in mind. You implement interface, register it (in composition root) and framework calls you.
Framework is the consumer of the client code.
It CREATES instances of the client code!
It hides registration details that would be explicitly visible in composition root (no room for 2 in container)
How to unregister (clear out) previous registrations for an object?
It’s hard to know lifetime of the dependency (wrong assumptions could be made)
Respects Open/Closed Principle, Liskov comes into play