您能否展示通过ita聚合根访问聚合中实体内容的简单示例?我不清楚您如何表示聚合权限以反映这些概念。 tia。

最佳答案

通常,您可以将其封装在Aggregate合同中公开的命令中。

例如,对于订单汇总,您可以使用从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);
    }
}

10-08 13:21