This is a question for those times you are creating the read model by event handlers.
The question comes down to : How can a Event Handler draw from other sources of information than what is contained in the handled event itself to construct a read model?
I have two aggregates, Person and Address. A person can be associated to different addresses (Home, Work, etc.)
So I have a read model table Addresses (ID, line1, line2, line3, etc.)
I also have a read model table PersonAddresses (PersonID, AddressID, line1, line2, line3) - Duplicated, denormalized data.
When an Address is created, I dispatch an event AddressRegistered with the address info (ID, Line1, Line2, etc.).
When an Address is associated to a Person, I dispatch an event AddressAssociated (with the PersonId, AddressId).
Then, I want to create the readModel.
When I receive a AddressRegistered event, I add an entry into the Addresses read model table.
When I receive a AddressAssociated event, I want to add an entry into the PersonAddresses read model table.
Though, I would like to have the address info as well (Line1, Line2, Line3) in the PersonAddresses table as my clien application will use it this way. But this info is not contained in the AddressAssociated event. This event only contains PersonID and AddressId.
What is the most recommended way of getting that information (Line1, Line2, Line3) for the associated Address in the AddressAssociated event Handler in order to populate the PersonAdresses read model table?
- In the domain, attach the address info (Line1, Line2, ...) to the AddressAssociated event so that it can be directly added into the PersonAddresses table ? That would require a domain service as it would need to look up multiple aggregates. (Address and Person are two aggregates)
- When adding entries in the PersonAddresses, retrieve the information beforehand from the Addresses read model table? Is it recommended that the read model read itself (eventual consistency, etc.) ?
- Something else?