Reputation: 179
Finally starting to get the hang of Domain Driven Design, and in my mind it makes sense to separate the persistance model (PM) from the domain model (DM).
Since mapping from PM to DM should be done in the repository and the DM should be immutable and not know about the PM, should I just create a factory function that takes all the parameters but now call the event?
The service layer converts DTO to DM by using the factory functions, then maps back to DTO when task if finished.
Or go with the easy way and create a factory function inside the DM that takes PM as a parameter, and the other way around?
My solution would be: Trade some purity and clearness from DDD, to make the design a more efficient and decrease the complexity.
Upvotes: 1
Views: 889
Reputation: 3260
The service layer knows about both all layers involved: DTO, DM, PM, and repository, so it is the best place to do all kinds of conversions.
In a typical flow, assuming you are acting on an API call, you would:
Upvotes: 1