I am currently designing and implementing a framework using Domain Driven Design concepts.
I am trying to put the Validation in the domain model layer.
Sometimes doing validation needs to access the database and query it, as an example :
"querying to check multiple column unique index"
With respect to this and the fact that queries should be written in the repository layer classes, It comes out that domain entities need to have references to their repository interfaces in the domain model layer in order to put the validation completely in the domain model layer.
I wonder if It is ok for domain entities to have access to repositories ?
And if it is not ok then how should this situation be handled?
I mean should such validation methods be moved to repository or Application Service Layers? If yes, is It ok to move the validation methods to those layers ?
Or as domain services can have access to repositories, should we create domain services in the domain model layer for validation?
How should we handle It?
thanks in advance