通过聚合根访问实体:简单示例? [英] Accessing entities via aggregate root: simple example?

查看:80
本文介绍了通过聚合根访问实体:简单示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Can you show simple example of accessing the contents of an entity in an aggregate via ita aggregate root? I am not clear on how you would represent the Aggregate permissions to reflect these concepts. tia.

推荐答案

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

You typically would encapsulate this in commands that the Aggregate exposes on its contract.

例如,对于订单汇总,您可以使用从GUI获取的数据添加订单行。

For example, with an Order Aggregate, you might add OrderLines using data obtained 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);
    }
}

这篇关于通过聚合根访问实体:简单示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆