什么是聚合根? [英] What's an Aggregate Root?

查看:182
本文介绍了什么是聚合根?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力解决如何正确使用存储库模式。聚合根的核心概念不断涌现。当搜索网页和堆栈溢出以帮助解决一个聚合根时,我会继续找到关于它们的讨论,以及对包含基本定义的页面的死链接。

I'm trying to get my head around how to properly use the repository pattern. The central concept of an Aggregate Root keeps coming up. When searching both the web and Stack Overflow for help with what an aggregate root is, I keep finding discussions about them and dead links to pages that are supposed to contain base definitions.

在存储库模式的上下文中,什么是聚合根?

In the context of the repository pattern, what is an aggregate root?

推荐答案

在上下文中的存储库模式,聚合根是客户端代码从存储库中加载的唯一对象。

In the context of the repository pattern, aggregate roots are the only objects your client code loads from the repository.

存储库封装了对子对象的访问 - 从调用者的角度来看,它自动加载它们,或者在同一时间加载根目录或实际需要的时候(与延迟加载一样)。

The repository encapsulates access to child objects - from a caller's perspective it automatically loads them, either at the same time the root is loaded or when they're actually needed (as with lazy loading).

例如,您可能有一个 Order 对象,它将操作封装在多个 LineItem 对象上。您的客户端代码将不会直接加载 LineItem 对象,仅包含它们的 Order ,这将是聚合根您的域的该部分。

For example, you might have an Order object which encapsulates operations on multiple LineItem objects. Your client code would never load the LineItem objects directly, just the Order that contains them, which would be the aggregate root for that part of your domain.

这篇关于什么是聚合根?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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