What makes more sense. Having a service layer reference multiple repositories (acting as a facade), or having a repository group multiple related entities together. For example I have the following entities and I’m not sure how to structure things.
Entities (POCO’s)
- Survey
- SurveyGroup
- SurveyQuestion
- SurveyAnswer
Q1. Should each of these entities have their own respository? SurveyQuestion cannot exist without being in a SurveyGroup, and SurveyGroup cannot exist without being in a Survey.
Q2. Should I make one Repository for Survey, SurveyGroup, and SurveyQuestion, and an additional one for SurveyAnswers?
Q3. Should I make a separate repository for each one and create one service class (SurveyService) that references them all?
I’m not sure what is considered “best practice” for something like this.
The general rule of thumb in DDD is to create a repository for every Aggregate Root.
In your example, it looks like
Surveywould be the Aggregate Root, so create aSurveyRepository.