DDD根聚合根是什么? [英] DDD Which is the root Aggregate root?

查看:284
本文介绍了DDD根聚合根是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很多示例(例如订单和订单行)很有意义,例如:

Lots of examples like order and order lines makes sense, like:

Order 包含 OrderLines
Customer 的AR
AR 包含 Orders

问题是,包含<$ c的 AR 是什么$ c>客户?
我想可能是商店之类的东西。

Question is, what is the AR that contains Customer? I guess it can be something like "shop".

因此, shop.AddCustomer(customer) ...

但是,如何购买?
如果它是 AR (实体),则具有ID,因此 shop.GetById(shopId)。如果我只有一家商店,这将如何持久化?

but, how to get shop? If it's an AR (entity) it has an id, so shop.GetById(shopId). If I only have one shop, how does this work with persistence?

我应该有一张只有一行的桌子(商店)吗?
Shop 是一个内存对象,其中包含 Customers

Should I have a table (shops) with one line? Shop is an in-memory object with a collection of Customers?

推荐答案

您在那儿弄错了。 聚合不包含其他聚合!它们只能按ID引用。

You got that wrong there. Aggregates do not contain other aggregates! They can only reference them by ID.

聚合是一组紧密相连的实体和值对象有关。聚合在它们周围形成一致性边界。 聚合根是该聚合中可全局寻址的根实体。因此,在具有 Order OrderLines 的示例中, Order

An aggregate is a group of entities and value objects that are closely related. The aggregate forms a consistency boundary around them. The Aggregate Root is the root entity in that aggregate that is globally addressable. So in your example with Order and OrderLines, Order could indeed be the AR.

客户,而只引用 Orders 如果是单独的聚合,则按ID。

Customer on the other hand, would only reference Orders by ID if it is a separate aggregate.

要检索聚合,通常使用存储库。通过指定聚合的ID或其他一些合适的搜索参数,您可以通过存储库加载聚合。

To retrieve an aggregate, you typically use a Repository. You load an aggregate through the repository by specifying the ID of the aggregate, or some other suitable search parameter.

这篇关于DDD根聚合根是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆