I'm developing real-time chat functionality as part of an application. As per my initial structure I had 3 Domain Objects as part of this new context:
Thread
(aggregate root)ThreadMessage
(entity, part of theThread aggregate
as a collection; has a ParticipantId to know it's sender)ThreadParticipant
(entity, part of theThread aggregate
as a collection)
The problem arose when I realised I need the Thread
and ThreadParticipant
relationship to be logically (and in the persistance store) many-to-many. My User
(from the Identity bounded context) will hold a reference to a ThreadParticipant
's ID.
The more I thought the less sense it made for the ThreadParticipant
to be a child entity in Thread
as it it can obviously live on it's own being in a many-to-many relationship with Thread
.
My question is is it bad to create a separate bounded context with ThreadParticipant
as the aggregate root, which will hold a collection of Thread
IDs, for example. And if so, what will happen to the Message
entity from the Thread
aggregate root- it will hold a reference to the Participant
aggregate root which will cause a circular reference between both contexts.
void main()