Imagine an instance where we have an entity that has a collection of value objects.
If we were to add (say the domain concept is to assign) an additional record value object to the collection we would have something like:
entity.assign_record(...)
that would raise a:
class RecordAssignedEvent(...)
Straight forward.
Now imagine a situation where the invariant requires that an entire collection needs to be replaced. Let's say an assign method would now replace all the current records in the entity.
ie.
entity.assign_records(list <records>)
Would it be better to raise a single event:
class RecordsAssignedEvent:
contains details of all records updated
or create a separate event per assigned record, then publish the collection together:
class RecordAssignedEvent(...)
My concerns are:
- The single RecordsAssignedEvent will contain a lot of data... imagine 10 records being assigned? 100?
- My domain events only contain primitive types. But if I raise as a single event, I'll be forced to create some DTO or similar to include as a collection. That DTO now needs to be available to any subscriber of the event. If I raise multiple events I can easily continue to limit to primitives.
In the DDDSample app there is a similar scenario where a Cargo has an itinerary made up of a number of legs (in this case the collection itself is a value object made up of value objects):
Is there any guidance in these situations on the granularity of domain events?