3

멀티 레벨 객체 모델을 기반으로 저장소 인터페이스를 고려하는 방법 :MVC : 내 개체 모델에서 멀티 레벨 의존성 체인을 가지고

조직 다음과 아이의 관계가 있습니다

Organization 
    .CompetitionGroups 
    .CompetitionGroups.Venues 
    .CompetitionGroups.Competitions 
     .Divisions.Games 
     .Divisions.Games.Participants 
     .Divisions.Games.Participants.GameSegments 
     .Divisions.SubDivisions... 
     .Divisions 
      .Teams 
      .Teams.Players 
      .Teams.Participants 
      .Teams.Participants.GameSegments 
     .VenueDates 

을 이것은 객체 모델을 엿볼 수 있지만 관계와 목록의 복잡성에 초점을 맞추고 있습니다.

내가 얻을 수없는 것은 작업 단위를 수행하기위한 요구 사항을 고려할 때 저장소 인터페이스를 고려하는 가장 좋은 방법입니다.

예를 들어 게임을 만들려면 venuedate와 두 명의 참가자가 필요합니다. GamesController에 IGameRepository, IVenueDateRepository 및 IParticipant 저장소가 필요하다는 의미입니까? 그것들을 하나의 저장소에 넣어야합니까?

또한 소비 사례는 어떻게됩니까? 예를 들어, 팀 팀 일정을 표시하려면 해당 팀의 모든 참가자, 해당 참가자의 모든 게임 및 참가자의 모든 GameSegments가 필요합니다. 그것들을 개별 리포지토리에 포함 시키면 효율적인 질의를 수행하는 방법을 알 수 없습니다.

다른 케이스에 초점을 맞춘 리포지토리가 있다는 것을 의미합니까? 예를 들면 :

public interface IScheduleRepository { 

    public ICollection<Game> GetScheduleForTeam(Team team); 

    // More consumption methods 
} 

public class ScheduleRepositry : IScheduleRepository { 

    public ScheduleRepository (ModelContext context) { 
     // Do stuff with context 
    } 

    public ICollection<Game> GetScheduleForTeam(Team team) { 

     return (
      from p in context.Participants 
      where ((p.Game.VenueDate != null) && 
       (p.TeamId == team.Id)) 
      orderby p.Game.VenueDate.StartTime 
      select p.Game).ToList(); 
    } 

    // more consumption methods 

} 

public interface IGameRepository { 

    public void AddGame(Game game); 

    // More crud methods 
} 

// Not showing games repository 

public class GamesController : Controller { 

    public GamesController (IGameRepository gamesRepo, 
     IVenueDateRepository venueDateRepo, 
     IParticipantRepository participantRepo) { 

     // do stuff with repos here 
    } 

    [HttpPost] 
    public ActionResult AddGame(Game game) { 

     // Skipping validation logic 
     // this? 

     VenueDate = venueDateRepo.Add(game.VenueDate); 
     foreach (Participant p in Game.Participants) 
     { 
      participantRepo.Add(p); 
     } 

     Game = gamesRepo.AddGame(game); 

     // or this? 
     // how would the game repo know to persist 
     // the children elements? is that tight coupling? 

     Game = gamesRepo.AddGame(game); 
    } 

    // more consumption methods 

} 

내 문제는 내가 아직 저장소가 연결된 객체 모델을 기반으로 이해가 어느 정도를 감안하는 이해가 안된다. 나는 여기에 조언을 좀하고 싶습니다.

답변

0

aggregate roots 및 경계를 정의한 다음 루트 주변에 리포지토리를 디자인해야합니다. (등록 후 무료) this book이에 좋은 (그리고 간단한) 장 작업 단위를 수행하기위한로서

이 있습니다

, 나는 일반적으로이 서비스 계층의 기능을합니다. 따라서 컨트롤러는 서비스에 대한 참조를 가지며 저장소 (들), 엔티티 (들), 작업 단 (unit) 등의 오케스트레이션을 처리합니다.