Operations on objects in the aggregate root

If I developed AR, as shown below, what do you think I should say about updating a property in one of the objects of the order line?

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

This is the ordered root of order

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); } } 
+3
source share
1 answer
 Order order = orderRepository.find(orderId); order.changeTitle(orderLineId, "New title"); 

Where 'orderLineId' can be a line number or an index or something else if it is an aggregate-root-specific (rather than a global id). See this answer to a similar question.

+1
source

Source: https://habr.com/ru/post/972635/


All Articles