Changes to child objects managed by child objects,

I find it difficult to understand how Aggregate Root will track changes in child objects.

Let's say I have a collection:

  • Order (root)
  • OrderLineItem

With class Order is the aggregate root. How will I track changes made in each OrderLineItem through the Order class?

When I do a repository (implementation), for example. a OrderRepository (because only the aggregate root can have a repository right?), how OrderRepository my OrderRepository track changes of each OrderLineItem ?

Example:

  • Recently added but not listed in DB
  • Edited, but committed to DB
  • Edited but not executed for DB

How do you guys handle this?

+6
source share
1 answer

when the Order class is now an aggregated root, how will I track the changes made on each OrderLineItem through the Order class?

All changes to the Order aggregate, including OrderLineItem , must pass through the aggregate root. Thus, an aggregate can maintain its integrity. Regarding change tracking, it depends on your save implementation. If you use ORM, such as EF or NHibernate, ORM will take care of tracking changes. If you use an event source, then changes are tracked explicitly as a sequence of events, usually supported by the aggregate in OOP implementations. If you use SQL directly, you can also avoid tracking changes and updating the entire population with each commit.

and when I create the repository (implementation), say OrderRepository, because only the root aggregate can have the repository correctly?

Yes, repository per aggregate.

+6
source

Source: https://habr.com/ru/post/945452/


All Articles