我读了Eric Evan的关于DDD的书,聚合章节. 在处理Order / OrderLine示例时,声明: When both users have saved their changes, an Order will be stored in the database that violates the invariant of the domain model. An important
在处理Order / OrderLine示例时,声明:
When both users have saved their changes, an Order will be stored in the
database that violates the invariant of the domain model. An important
business rule has been broken. And nobody even knows. Clearly, locking
a single line-item isn’t an adequate safeguard. If, instead, we locked
an entire Order at a time, the problem would have been prevented.
我很清楚Aggregate的本质是用单个包装的数据库事务来保护不变量.
但是,是否应该在数据库端使用读锁定指定每个聚合,以防止潜在的并发问题(竞争条件),同时由多个用户同时修改此聚合?
制作聚合的真正含义是为数据库端的读锁收集一些元素吗?
对此的任何澄清都会让我感到高兴.
不,这两者是正交的:聚合设计的目标是建立一致性边界并保护该边界内的不变量.锁定设计的目标是在应用程序中实现适当的并发级别.
这意味着使用相同的聚合设计,不同的锁定机制可能有意义(取决于应用程序的非功能性要求).