Dependency inversion
Instead of a persistence layer, we’ll talk about a persistence adapter that provides persistence functionality to the domain services. Figure 7.1 shows how we can apply the Dependency Inversion Principle to do just that:
Figure 7.1 – The services from the core use ports to access the persistence adapter
Our domain 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 domain services and the persistence code. Let’s remind ourselves that we’re adding this layer of indirection in order to be able to evolve the domain code without...