【发布时间】:2013-11-04 13:47:12
【问题描述】:
最初我的 DDD 存储库类似于以下示例:
class PersonRepository {
Person findByID(id)
List<Entity> findAll()
List<Entity> findWithRegex(String)
}
Service 内部提供了将 Entity 对象转换为 DTO 对象的 GUI
现在我正在尝试进入 CQRS。看了其他的例子,看来我的repo应该是这样的:
class PersonReadModel {
Person findByID(id)
List<DTO> findAll()
List<Entity> findWithRegex(String)
}
仅使用 DDD,我的存储库仅返回 Entity 和 List 对象。对于 CQRS,由于许多读取仅用于 UI,因此有许多读取操作会返回直接 DTO,因此 PersonReadModel 看起来不像传统的 DDD 存储库。
这个假设正确吗?我应该让 PersonReadModel 只返回 List 并保留 PersonRepository 返回的 Entity 和 List 对象吗? PersonReadModel 是否应该是包含指向根聚合的内部存储库的链接的服务?
我可以将 DTO 与其实体相关联,因为它们都有一个身份字段。但是,我担心显示的 DTO 与我的域模型中存在的实体的 revision 不同。我见过的所有 CQRS 示例都有 DTO 和带有 identity 字段但没有 revision 的实体。
我应该关注修订吗?
我的猜测是,应用层中的 GUI 代码将构建带有 DTO 和 revision 的消息,并且域层将使用它来确保请求的命令是使用最新版本构建的版本。
【问题讨论】:
-
“修订”是什么意思?
标签: domain-driven-design cqrs ddd-repositories