What is the best way to fill updated data from one aggregate root to another?

171 views
Skip to first unread message

Andrey Ladniy

unread,
Aug 3, 2017, 7:22:40 AM8/3/17
to DDD/CQRS

I try understand what is the best way for filling property from one Aggregare Root to another.

I have Model Aggregate RootCategory Aggregate RootFilter Aggregate Root

Every Model can have some Filter list, and can be in one of the CategoryCategory can have a Filter for inheriting to the Model. When Category property of the Model is updated, Filter must be inherited from Category to the Model, and when Filter property is updated in the Category, all Models from that Category must inherit new value. All inherited Filters can't be updated, but manually added filters can be edited.

One way I "invent" is using Process manager with state which contains Category filter and Models list.

So I will have such behavior:

  1. Category AR UpdateCategoryFilter (command) -> CategoryFilterUpdated (event)
  2. Model AR AddCategory (command) -> CategoryAdded (event), RemoveCategory (command) -> CategoryRemoved (event), InheritFilter (command) -> FilterInherited (event), RemoveInheritedFilter (command) -> InheritedFilterRemoved (event)
  3. Filter AR CreateFilter (command) -> FilterCreated (event)
  4. Process Manager FilterInheritance have correlationIdResolver by categoryId, triggers on [CategoryFilterUpdatedCategoryUpdated] events

PM behavior is like:

on event use current State(filter, models) =>
  if CategoryFilterUpdated(categoryId, newFilter) =>
    set new State(newFilter, models) {
      models.forEach(send InheritFilter(model, newFilter))
    }
  if CategoryAdded(modelId, categoryId) =>
    set new State(filter, models.add(modelId)) {
      send InheritFilter(modelId, filter)
    }
  if CategoryRemoved(modelId, categoryId) =>
    set new State(filter, models.remove(modelId)) {
      send RemoveInheritedFilter(modelId, filter)
    }

Is this a right way? Is there some other ways?


xiety

unread,
Aug 8, 2017, 3:36:22 AM8/8/17
to DDD/CQRS
Depends on how you will use this data. Sometimes, it is possible to create a domain service which will listen to events and build a special read model with all required information in useful form.

Andriy Drozdyuk

unread,
Aug 16, 2017, 10:29:20 PM8/16/17
to DDD/CQRS
I'm not sure I understand your question completely, but it seems like you are going in the right direction:

Aggregate --- (events) --> Process Manager --- (commands) ---> Aggregate
Reply all
Reply to author
Forward
0 new messages