Sudarshan
Sudarshan

Reputation: 8664

Operations on entities within a aggregate root

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);
    }
}

Upvotes: 4

Views: 330

Answers (1)

Dmitry
Dmitry

Reputation: 17350

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.

Upvotes: 1

Related Questions