I am using asp.net mvc with an entity framework and am starting to learn DDD. I am working on a project that contains reviews. Here is my domain model:
public class Survey { public int? SurveyID { get; set; } public string Name { get; set; } public decimal MinAcceptanceScore { get; set; } public int UserFailsCount { get; set; } public IEnumerable<SurveyQuestion> Questions { get; set; } public IEnumerable<Prize> Prizes { get; set; } public IEnumerable<SurveyAttempt> UserAttempts { get; set; } }
I need different parts of the polls for different views, so I created different ViewModels:
public class ShortSurveyViewModel { public int? SurveyID { get; set; } public string Name { get; set; } public int UserFailsCount { get; set; } public IEnumerable<SurveyAttempt> UserAttempts { get; set; } } public class ShortSurveyWithPrizesViewModel { public int? SurveyID { get; set; } public string Name { get; set; } public int UserFailsCount { get; set; } public IEnumerable<SurveyAttempt> UserAttempts { get; set; } public IEnumerable<Prize> Prizes { get; set; } } public class SurveyEditViewModel { public int? SurveyID { get; set; } public string Name { get; set; } public decimal MinAcceptanceScore { get; set; } public int UserFailsCount { get; set; } public IEnumerable<SurveyQuestion> Questions { get; set; } public IEnumerable<Prize> Prizes { get; set; } }
What is the best way to build my architecture if I want to get the information needed for a matching type model in my survey repository?
Various solutions that I see:
The repository can return IQueryable to SurveyService, and the service can return a compliance model, but I do not dare that this is correct, because I think that view models should be created in the user interface, and not in the service.
Create three suitable classes in my domain. But now the domain will depend on the view and with each new view a new domain class must be created.
Get the full domain object and display only the properties necessary for a particular view. This is not good, because in my example, questions are needed in only one view, and it can be a heavy collection.
source share