Reputation:
Simple question: should Repository validate Entity before persisting it? Validate = check if all values match the rules (like Name is < 50 chars etc).
Upvotes: 3
Views: 1575
Reputation: 51634
In DDD every Aggregate should be responsible for its validity. There should never be an object in an invalid state. i.e. every Aggregate should reject any mutation that would lead to an invalid state.
Quoting from a great article on the topic, Validation in a DDD World, by Jim Bogard:
Simply put, if we control the operation side of the equation, why in the world would we allow our entities to get into an invalid state? Life becomes much more complicated if we start having “IsValid” properties on our entities.
Upvotes: 8