I have a design question in the "field" of CQRS / DDD.
I will not explain in depth the domain, but only what's needed.
It's a CONTACT domain, so it manages the contact informations of people and organisations.
A relation can exist between people and addresses. This relation exists in time so it can be active or inactive (has activeDate and inactiveDate). A relation can also be defined as the "preferred" one.
There are some ways a relation can be defined as the preferred one.
- It is the first active one.
- It has been defined as the preferred one explicitely.
- It is the next in line when another relation expires or is no longer the preferred one.
So the corresponding events :
- AddressLinkRegisteredEvent - depends on the active / inactive
- PreferredAddressLinkChanged
- AddressLinkUnregisteredEvent
- AddressLinkInfoChangedEvent - maybe the user set the Relationship as inactive
So for example the business rule : "There should be at most one preferred address at any time".
When the event Handler will receive the "AddressLinkRegisteredEvent ", how should it know that it should write this address as the preferred one, without duplicating the business rules ?
Or, when receiving the "PreferredAddressLinkChanged", how should it know to remove the "preferred" flag from the previous preferred address and apply it to the new one?
Thank you for your insights.