聚合根中实体的操作 [英] Operations on entities within a aggregate root

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

问题描述

如果我设计了如下所示的AR,您如何认为应该更新一个订单行对象之一中的属性?

If i have designed an AR like the below, how do you think i should go about say updating a property in one of the order line objects ?

例如我如何更改我的订单行之一的标题(示例问题)

For Example how can i change the title for one of my order lines (example question)

这是订单汇总根

public class Order
{
    private readonly int id;
    private readonly Customer customer; // Customer is another Aggregate
    private readonly IList<OrderLine> orderLines;
    private readonly IOrderLineFactory orderLineFactory;

    public Order(int id, Customer customer, IOrderLineFactory orderLineFactory)
    {
        this.id = id;
        this.customer = customer;
        this.orderLines = new List<OrderLine>();
        this.orderLineFactory = orderLineFactory;
    }

    public void AddOrderLine(Item item, int quantity)
    {
        OrderLine orderLine = orderLineFactory.Create(this, item, quantity);
        orderLines.Add(orderLine);
    }
}


推荐答案

Order order = orderRepository.find(orderId);
order.changeTitle(orderLineId, "New title");

其中 orderLineId可以是行号或索引,只要是聚合的-root特定的(不是全局ID)。请参阅对类似问题的答案。

Where 'orderLineId' can be a line number or an index or something else as long as it is aggregate-root-specific (not a global id). Please see this answer to a similar question.

这篇关于聚合根中实体的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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