This question is about DDD and Event Sourcing where entities within an Aggregate other than the Aggregate Root itself have event-generating behaviour. Whether this is appropriate, and if so how to implement it.
I'm trying to model a DeliveryRun
Aggregate Root (AR), which is the trip a vehicle makes to perform a delivery. Before it departs, it must have an up to date DeliveryManifest
. The "up-to-dateness" of it suggests to me that the DeliveryManifest
be an entity within the DeliveryRun
consistency boundary defined by the AR.
Okay so far.
I'm using an Event Sourcing approach for this - the approach as taught by Greg Young and implemented in the Regalo library. This means the AR (DeliveryRun
) need not actually have any entities if there is no behaviour for them (e.g. a SalesOrder
may not have SalesOrderLines
, because it records events such as ItemsAdded
/ItemsRemoved
instead).
However, there is to be some logic around the DeliveryManifest
. Specifically, once the manifest has first been requested, when items are added to the delivery, a new version of the manifest needs to be created. This means we can ensure drivers don't depart without the most up-to-date manifest available.
If I were to encapsulate the logic inside the DeliveryManifest
object (which won't be serialised and stored; we're using Event Sourcing and it's not the AR), how do I capture events?
Should the events be generated by the DeliveryManifest
entity, but saved against theDeliveryRun
itself (which would then need to know how to replay those events into theDeliveryManifest
when loaded from the event store)?
Should there be no DeliveryManifest
(except perhaps as a data structure) and all the logic/events be implemented directly by the DeliveryRun
?
Should the DeliveryManifest
be it' own AR and make sure the DeliveryRun
is told of the current manifest's ID? Since that takes the manifest object outside the consistency boundary of theDeliveryRun
, I would need to build some event handling to subscribe to changes in theDeliveryRun
that are relevant to the manifest so it can be updated/invalidated etc accordingly.
Implement a different style for capturing the events similar to Udi's DomainEvents pattern. This means changing the Regalo library, though I think it could be made to support both patterns fairly easily. This would allow all events generated by all entities within the aggregate to be captured so they can be saved against the AR. I'd need to think of a solution for loading/replaying though...
--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.