The Role of Dependency Injection
Learn how dependency injection can play a role in developing clean software architecture.
We'll cover the following
The package structure described previously goes a long way towards a Clean Architecture, but an essential requirement of such an architecture is that the application layer does not have dependencies to the incoming and outgoing adapters, as we have learned in the chapter “Inverting Dependencies”.
For incoming adapters like our web adapter, this is easy because the control flow points in the same direction as the dependency between adapter and domain code. The adapter simply calls the service within the application layer. In order to clearly demarcate the entry points to our application, we might want to hide the actual services between port interfaces nonetheless.
For outgoing adapters, like our persistence adapter, we have to make use of the Dependency Inversion Principle to turn the dependency against the direction of the control flow.
Get hands-on with 1400+ tech skills courses.