Dependency Inversion
Instead of a persistence layer, we will talk about a persistence adapter that provides persistence functionality to the application services.
The following figure shows how we can apply the Dependency Inversion Principle to do just that:
Figure 6.1: The services from the core use ports to access the persistence adapter
Our application services call port interfaces to access persistence functionality. These ports are implemented by a persistence adapter class that does the actual persistence work and is responsible for talking to the database.
In hexagonal architecture lingo, the persistence adapter is a "driven" or "outgoing" adapter, because it's called by our application and not the other way around.
The ports are effectively a layer of indirection between the application services and the persistence code. Let's remind ourselves that we are adding this layer of indirection in order to be able to evolve the domain code without...