gpt4 book ai didi

domain-driven-design - 通过聚合根 : simple example? 访问实体

转载 作者:行者123 更新时间:2023-12-04 11:32:49 25 4
gpt4 key购买 nike

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

最佳答案

您通常会将其封装在聚合在其契约(Contract)中公开的命令中。

例如,对于 Order Aggregate,您可以使用从 GUI 获得的数据添加 OrderLine。

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

关于domain-driven-design - 通过聚合根 : simple example? 访问实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/714509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com