I have rather CQRS related question than axon related, but maybe you can give me some tip.
I have two ARs, let’s say A and B, which have one to many relationship
- A define some settings (for example, minimal/maximal value etc…)
- B store some value which must satisfy settings of A
So, there can be a lot of B’s which are “bound” to some A.
I have following commands and events:
CreateaA(aId, min, max)
-> ACreated(aId, min, max)
ChangeA(aId, min, max)
-> AChanged(aId, min, max)
CreateB(bId, aId, initialValue)
BCreated(bId, aId, initialValue, min, max)
How should CreateB command be handled? Should i use A read model inside handler to find A aggregate, get its settings and apply BCreated event?
Also I want to notify all B instances if A’s settings is changed … this can be solved by saga, which listen for AChanged event and then using read model gets all B ids and
send commands to update settings of all B instances, right?
I know that A aggregate root is a simple CRUD and can be implemented that way and only publish events, but that doesn’t matter now. There can be better examples, but I wonder how
should I share data between ARs? Should I pass IDs in commands, load instances using read model in command handlers and pass that data to events? Is there any better way?
NOTE: A and B cannot be in same aggregate.