I have question regarding to use data from one aggregate in another in DDD. Imagin you have two bounded context Project which encapsulating all data about projects and plan responsible for managing work plan for users. One of invariatnts say: project can be assignate only if is in active state.
simplified system design
I think it is simple example but i don't know what solution will be the best one.
I keep few solution in mind but i'm not sure which one will be the best or maybe is better one.
First:
def assign_hanlder(command):
project = project_repository.get(command.project_id)
assignation = assignation_repository.get(command.assignation_id)
assignation.assign_project(project.id,project.status)
assignation_repository.save(assignation)
Use project repository in assignation handler and pass data from project agregate into assign_project method. I'm not sure because assignation handler have knowledge about implementation details of project now.
Second:
def assign_hanlder(command):
project = project_query.get(command.project_id)
assignation = assignation_repository.get(command.assignation_id)
assignation.assign_project(project)
assignation_repository.save(assignation)
Use some query object to get project value object, project query interface can be close to assignation aggregate. But also i don't know it is good approach in DDD to make query object like this.
Third: Maybe better way is to create domain service to encapsulate this logic? But still we have to use data from one aggregate in another.
Another problem is what if project state will be changed while lifecycle? This case will be probably depends on business. But assume project in assignation aggregate should be syncronized with project agregate, it can be done by the event but also i'm not sure aboute that solution becouse for me we have two source of truth.
I'm pretty sure there is some misunderstanding here. Maybe i cannot decouple these aggregates?
Thanks for help. ;)