Accessing Entities Through a Common Root: A Simple Example?

Can you show a simple example of accessing the contents of an object in an aggregate through its own root? I do not quite understand how you represent Aggregate permissions to reflect these concepts. TIA.

+5
domain-driven-design
source share
1 answer

Usually you encapsulate this in teams that aggregates in your contract.

For example, using Order Aggregation, you can add OrderLines using data received from your GUI.

// 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); } } 
+7
source share

All Articles