Create all Entities from the AR or let Entities create their own children

Hi, I’m starting my first spike into the ddd/cqrs/es world, I’m using the commondomain ARbase and the repository recomended by GES and GES. I think I’ll be using this in my tag line for a little bit.

Lets say I pass a command to the constructor of an AR and that command is translated into a) some property sets on the AR b) The creation of some childEntities, and c) The creation of some childEntities on those childEntityies.

Let me explain my reasoning briefly. When creating an AR I want to make sure that all it’s invariants are in place and those invariants consist of at least one child and one grand child. I guess that’s obvious, but whatever.

So my question is this, in the constructor I emit a I’mCreatedEvent. then I call CreateChild(initialCommand.CreateChildCommand). In side there I process the createChildCommand and emit a ChildCreatedEvent. I create that child by just passing on the command to the constructor of the child. Should that command include the createGrandChildCommand? and should the Child then be emiting events like I’mCreated? Or should there be these methods on the AR: CreateChild(command), CreateGrandChild(command) and only emit events from the AR.

If you are still following let me give you my actual domain as the above sounds ridiculous.

We are basically creating an email system.

The only way I can figure it is we have a

Conversation

– Subject -string

– ConversationType -TypeValueObject

– ConversationSender -ConversatonParticipant

– ConversationRecipients -collection of ConversationParticipants

– Messages -collection of messages

Message

– body -string

– MessageSender -MessageParticipant

– MessageRecipients -collection of MessageParticipants

It stands to reason that you can’t have a conversation without at least two participants. Also seems you must have at least one message. Furthermore, one can’t have a message with out at least a sender and a reciever.

So in order to create a new conversation I really need to create the Conversation, a Sender, a recipient, a message, a message sender, and a message recipient. Then I have a conversation in a logical state.

SO

I have a

Conversation.AddSender(CreateConversationSenderCommand command)

– creates a ConversationParticipant and sets ConversationSender to this object

– Emits a ConversationSenderCreatedEvent and puts the properties of the new ConversationParticipant on the event

Same for Recipients

Same for a Message

However should I have

Same for a MessageSender ? or should the CreateMessageCommand have the data to create the MessageSender and MessageReceiver?

Ug, it still doesn’t seem very clear. But it’s the best I can do.

If you have any thoughts I’d be very appreciative

R