One of my aggregates contains multiple entities of the same class. Most events apply only to one of these entities, so I end up doing something like this:
@EventHandler
public void handle(final Event event) {
if (event.getEntityId().equals(id)) {
…
}
}
It seems very unnatural. Is there a better way to do this ?
This should definitely work, although be careful with the serialized form of this event. It is a bad idea to have a property “entityId” in the serialized event. Always make sure you use a property name with functional meaning, such as “orderLineId”.