Dependency Inversion in Practice
Wire adapters to the core with dependency inversion.
Inversion vs Injection
People conflate two distinct ideas. Dependency Injection is a technique: pass collaborators in rather than constructing them. Dependency Inversion (the D in SOLID) is a principle: high-level policy and low-level detail both depend on an abstraction, and the abstraction is owned by the high-level module. This lesson is about making the second one real — wiring concrete adapters to a core that defines the interfaces.
The Principle, Precisely
DIP states:
- High-level modules should not depend on low-level modules. Both depend on abstractions.
- Abstractions should not depend on details. Details depend on abstractions.
The subtle part: the interface belongs to the consumer, not the implementer. Your domain declares PaymentGateway; the Stripe adapter conforms to it — not the other way around.
All lessons in this course
- From Layered to Clean Architecture
- Ports and Adapters Explained
- Use Cases and Application Services
- Dependency Inversion in Practice