I am trying to understand hexagonal architecture through an example of Repository
.
In this setup I have the following layers: framework (infrastructure) -> application -> domain.
I have User
in the domain part, lets say I want to validate the User
if there aren't any duplicate through a DuplicateUsernameValidator
. In order to get this information I need this information from somewhere. I have added a interface UserRepository
again in the domain layer, this way it can be solved in the layer above.
This is the part where it gets tricky for me. I want to implement the logic of UserRepository
, but for me it doesn't make sense to implement this in the application layer, because the persistence context is in the infrastructure layer (e.g. JdbcUserRepository
or JpaUserRepository
).
But if I understand hexagonal structure correctly I can't implement the UserRepository
interface directly in my infrastructure layer, because the infrastructure layer shouldn't be aware of the domain layer.
What am I missing?