Hi,
I often read in this group that it is bad to insert Value Object in domain event.
But in case of Event sourcing approach, it seems that easier to use value object inside event, otherwise,
you have to convert value object to DTO and reverse operation (value object to dto to apply event from aggregate root,
and dto to value object to read event inside aggregate root in order to apply modification in internal fields)
Simplified Exemple :
public class Organization [AR]
{
private ContactAddress contactAddress;
....
public void modifyContactAddress(ContactAddresss contactAddress)
{
// here somme preconditions validation
...
apply(new ContactAddressModifiedEvent(new ContactAddressDTO(contactAddress.name, contactAddress.email, ... )));
}
@EventHandler
void handle(ContactAddressModifiedEvent event)
{
this.contactAddress = new ContactAddress(event.getContactAddressDTO().name, event.getContactAddressDTO().email, ...);
}
}
Obviously, this is not a good example here, because it is too simple, but if you have to call a method on aggregate with more complex VO objects,
you have to use this artificial conversion, just to avoid VO in event.
I have noticed that In IDDD sample project, made by Vaughn Vernon (Implementing DDD book), he puts direclty VO inside domain event.
How can you solve this problem ?
Best regards,
Baptiste.