cqrs - How to "join" two Aggregate Roots when preparing View Model? -
assume book
, author
aggregate roots in model.
in read model have table authorsandbooks
list of authors , books joined book.authorid
when bookadded
event fired want receive author
data create new authorsandbooks
line.
because book
aggregate root, information author
doesn't included in bookadded
event. , cannot include because author
root doesn't have getters (according guidelines of examples , posts cqrs , event sourcing).
usually receive 2 types of answers on question:
- enrich domain event data need in event handlers. said cannot aggregates roots.
- use available data view model. i.e. load
author
view model , use buildauthorsandbooks
row.
the last 1 has problems concurrency. author data can not available in view model @ time bookadded
event handling.
what approach use solve this? thank you.
as general advice, let event handlers idempotent , make sure can deal out of order message handling (either re-queuing or building in mechanisms fill in missing data). on other hand, question why author , book such desperate aggregate roots. maybe should copy author upon adding book (what f* "adding book", how's command). problem these made-up examples. descend real world, doubt problem exists.
Comments
Post a Comment