I have a simple examle domain of two aggregate roots and one regular entity.
Tenant
, UserGroup
and User
where in this particular sample the Tenant
and User
make up for the two AggregateRoots.
When a command is received from the UI/Service layer it reaches the command handler which manipulates the write only domain.
You could say that User
isn't supposed to be an AggregateRoot at all but since it will be referenced by others, it cannot be a regular entity. (yes?)
These two AggregateRoots need to communicate. A User
cannot be created without belonging to a UserGroup
, which is an entity in the bounded context of Tenant
. Presumably, we can create, since it is a simple constraint, a User through the constructor. User.Create(TenantId, UserGroupId)
It generates a DomainEvent
with Date, AggregateVersion and AggregateId (of the user). Now we get to the blurry parts.
Open committing this event into the store, this event is broadcasted onto the bus (memory, whatever). It this the point where domain's event handlers, similar to command handlers, catch the user created and notify/manipulate the Tenant
's UserGroup
to add the UserId
?
Are my thoughts about solving this going into the entirely wrong direction?