访问不是聚合根的实体

发布于 2024-10-15 00:37:00 字数 345 浏览 2 评论 0原文

我正在看 DDD,我有一些想法。在购物网站上,我有典型的订单。

public class Order
{
    public ICollection<OrderRow> OrderRows { get; set; }
    public ICollection<Payment> Payments { get; set; }
    ...
}

订单付款似乎是很自然的事情。下订单或处理订单时,付款是订单的一部分。

但后来管理员想要单独处理付款。例如,在管理界面中有需要处理的付款列表。

我该怎么做?是否应该将付款从订单中删除并作为其自己的根聚合?

I'm looking at DDD and I have some thoughts. On a shopping site I have the typical Order.

public class Order
{
    public ICollection<OrderRow> OrderRows { get; set; }
    public ICollection<Payment> Payments { get; set; }
    ...
}

Payments seem to be natural to place on the Order. When placing an order or working with the order, payments is a part of the order.

But later an administrator want to handle payments separately. E.g. in the administration interface have list of payments which needs to be handled.

How should I do this? Should Payments be removed from the order and be its own root aggregate?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

油焖大侠 2024-10-22 00:37:00

我的理解是,聚合可以并且将会重叠,从而允许您定义对当前操作的业务上下文最有意义的聚合。

因此,在这种情况下,是的,当按照订单进行工作时,您会将付款公开为订单聚合的一部分,但这并不妨碍您拥有一个专用的 PaymentRepository,将付款公开为聚合根。

My understanding is that aggregates can and will overlap, allowing you to define the aggregate that makes the most sense for the business context of the current operation.

So in this instance, yes, when working in terms of Order you'd expose Payments as part of the Order aggregate, but this doesn't prevent you from also having a dedicated PaymentRepository that exposes Payment as an aggregate root.

彼岸花ソ最美的依靠 2024-10-22 00:37:00

我认为 Payment 实体不属于 Order 聚合。正如您所写,您具有单独与付款一起使用的功能。这意味着付款不仅仅在订单上下文中使用。这意味着 Payments 不属于 Order 聚合:)。

但是,即使 Order 类不是 Order 聚合的一部分,也可以在 Order 类中拥有 Payments 属性。

I think that Payment entity doesn't belong to Order aggregate. As you wrote you have functionality that works with Payments separately. It means that payments are not used in Order context only. It means that Payments doesn't belong to Order aggregate :).

However it is possible to have Payments property in Order class even if it isn't a part of Order aggregate.

玩物 2024-10-22 00:37:00

如果没有订单就无法存在付款,那么付款就不是聚合根。

如果它不是聚合根,则从 OrderRepository 加载适当的 Order 对象并在其中的 Payment 实体上进行操作似乎具有最大的 DDD 完整性。

If a Payment can't exist without an Order then Payment isn't an aggregate root.

If it's not an aggregate root then loading the appropriate Order objects from an OrderRepository and operating over the Payment entities within seem to have the most DDD integrity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文