简体   繁体   English

将 CQRS 读取模型作为聚合实现是个好主意吗?

[英]Is it a good idea to implement CQRS Read model as an Aggregate?

Is it a good idea to implement CQRS Read model as an Aggregate?将 CQRS 读取模型作为聚合实现是个好主意吗? Or the read model should be kept as a POCO class?或者读取模型应该保留为 POCO 类?

In general when using CQRS you also use an event sourced design, so you don't have DDD entities (and by extension aggregates - at all).通常,在使用 CQRS 时,您还使用事件源设计,因此您没有 DDD 实体(以及扩展聚合 - 根本没有)。 Usually when using CQRS, you usually have a "command model" & a "query/read model" where the "command model" is some event queue that you may "snapshot" every X amount of time;通常在使用 CQRS 时,您通常有一个“命令模型”和一个“查询/读取模型”,其中“命令模型”是一些事件队列,您可以每 X 时间“快照”一次; and your query model(s) are just use case optimized search data stores where you aren't really interested in modelling a whole aggregate.并且您的查询模型只是用例优化的搜索数据存储,您对建模整个聚合并不真正感兴趣。

Now, even if you aren't using an event sourced system, and you are using DDD with just several "query/read models", chances are you want to create a DDD model and have aggregates on the "command model" and not the "read model", as your "command model" represents your domain view & understanding of your domain reflecting your (DDD) ubiquitous language.现在,即使您没有使用事件源系统,并且您只使用带有几个“查询/读取模型”的 DDD,您也有可能想要创建一个 DDD 模型并在“命令模型”上进行聚合,而不是“读取模型”,因为您的“命令模型”代表您的域视图和对域的理解,反映了您的 (DDD) 无处不在的语言。 The read/query model(s) are more oriented towards fine tuning performance for particular use cases (fast searches in a product catalog for example);读取/查询模型更倾向于针对特定用例(例如在产品目录中进行快速搜索)的微调性能; or for enriching/aggregating data with other "external-bounded context" information.或用于使用其他“外部有界上下文”信息来丰富/聚合数据。

As a side note, it is important to note that even though your query/read model is not intended to match 1:1 your aggregate, there is usually some correlation between your command aggregate, and your model DTO.作为旁注,重要的是要注意,即使您的查询/读取模型不打算与您的聚合 1:1 匹配,但您的命令聚合和模型 DTO 之间通常存在一些相关性。

Is it a good idea to implement CQRS Read model as an Aggregate?将 CQRS 读取模型作为聚合实现是个好主意吗?

Not really?并不真地?

An AGGREGATE is a cluster of associated objects that we treat as a unit for the purposes of data change. AGGREGATE 是一组关联对象,为了数据更改的目的,我们将其视为一个单元。

Since queries don't change the data, an aggregate is unnecessary ceremony.由于查询不会更改数据,因此聚合是不必要的仪式。 Putting a bunch of business data into an object just to take the data back out again doesn't make a lot of sense.将一堆业务数据放入一个对象中只是为了再次取出数据并没有多大意义。 Using a POCO/POJO/plain data structure gets the job done.使用 POCO/POJO/plain 数据结构可以完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM