DDD - Validation of unique constraint
Posted
by W3Max
on Stack Overflow
See other posts from Stack Overflow
or by W3Max
Published on 2010-04-18T02:03:14Z
Indexed on
2010/04/18
2:13 UTC
Read the original article
Hit count: 430
ddd
|validation
In DDD you should never let your entities enter an invalid state. That being said, how do you handle the validation of a unique constraint?
The creation of an entity is not a real problem. But let say you have an entity that must have a unique name and there is a thousand instances of this entity type - they are not in memory but stored in a database. Now let say you want to rename an instance.
You can't just use a setter... the object could enter an invalid state - you have to validate against the database.
How do you handle this scenario in a web environment?
© Stack Overflow or respective owner