I'd like to start by saying that I'm new to DDD and I'm creating a hobby system to practice some concepts, so this question might be trivial, but not so much for me.
I have the following scenario:
I have a given user that should be able to add exercise to the system, so I have two models
Exercise, and I have a method
addExercise which should create a new exercise and save it to database by using a repository. This method would mostly validate
Exercise data before saving to database, but there would be some validations regarding the user (such as verify if exercise wasn't previously created by this user)
I have thought about three ways to do that:
addExercisemethod to User model. Problems I see in this approach:
Usermodel would need to know about
Exercisein order to implement
Usermodel would need a repository to save the
UserService, since adding exercise is an operation from user, this seems ok, but when I start thinking about implementation, I would have
UserServiceto know about
ExerciseService, which I believe it is fine, but I'm afraid I might be missing something.
So, in my opinion, from a business point of view,
addExercise should be a method in
User model, but when I think about implementation details, it seems to make more sense option 3), but I want to know if this is in fact the correct option.
Also, I have some other questions:
I) Is it normal for a given model A to be able to create another model B or have a repository from a model B inside of it ? Or could a model A receive a repository that work with model A ?
II) Is it ok for a service A to receive repositories that work with model B ?