What's an Aggregate Root?

前端 未结 11 1328
臣服心动
臣服心动 2020-11-22 04:18

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

11条回答
  •  旧巷少年郎
    2020-11-22 04:47

    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).

    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.

提交回复
热议问题