Operations on entities within a aggregate root

我只是一个虾纸丫 提交于 2019-12-13 14:07:52

问题


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)

This is the 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);
    }
}

回答1:


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

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.



来源:https://stackoverflow.com/questions/11726673/operations-on-entities-within-a-aggregate-root

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!