Which layer should the repository classes go in? Domain or Infrastructure?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I guess that depends how You are going to rely on them.
Question is – are You going to allow Yourself to use repositories from inside of domain?
If so – then You are forced to put them in.
I myself like to put them outside of domain. So – typical life cycle of something looks like this =>
UI => Controller => retrieve aggregate root from repo => call logic through aggregate root => if new aggregate root created, add it to repo.
Sometimes controller calls application service that does some additional stuff besides just retrieving root and calling function on it. But idea is same – domain knows nothing about persistence.
While (as I see it) there’s nothing wrong with putting repos in domain (or at least abstractions of them), it makes Your domain more aware of persistence. Sometimes that can solve problems, but generally – that will definitely make Your domain more complex.
Use what seems more natural for You and be ready to switch Your ways any time.