Let's say I am designing a TODO application and therefore have an aggregate root called Task
. The business requires to keep a list of TaskLogEvent
that provides them with a history of how the task changed over time. As the Task
may have hundreds of these events, I will model this TaskLogEvent
as a separate aggregate root (I do not want to load these elements every time and I am not using any lazy loading mechanism).
Now anytime I want to do task.complete()
or any other opration modifying the Task
I want to create a new TaskLogEvent
. I have these options:
- Design a domain service that will make all changes to
Task
and create the event. Every comunication withTask
would have to get through this service. - Pass
TaskLogEventRepository
to any method inTask
so that theTask
itself can create the Event and save it into the repository. - Let an application service handle this. I don't think that is a good idea.
What would be the ideal solution to this situation? Where did I make mistake in my thinking process?