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.
source share