如果我设计了如下所示的AR,您认为我应该如何更新其中一个订单行对象?
例如,我如何更改其中一个订单行的标题(示例问题)
这是Order Aggregate Root
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);
}
}
答案 0 :(得分:1)
Order order = orderRepository.find(orderId);
order.changeTitle(orderLineId, "New title");
其中'orderLineId'可以是行号或索引或其他内容,只要它是特定于聚合根(不是全局ID)。请参阅this对类似问题的回答。