问题
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