Lesson 5: DIP and dependency injection
A business class that creates new SmtpMailer() inside itself is welded to one vendor: you cannot test it without a real mail server, and you cannot swap vendors without editing it. In this lesson we invert the dependency direction: the service depends on an interface, and the implementation is injec
DIP is like a wall socket: the lamp is not soldered to the power plant — both sides connect to a standard plug, so either side can be replaced without touching the other.
- Dependency Inversion Principle (DIP)
- Business logic depends on an abstract interface, and the concrete implementation is injected from outside — so infrastructure can be swapped and tested easily.
- constructor injection
- A pattern where the dependency enters as a constructor parameter and is stored in a private readonly field — whoever composes the app picks the implementation.