문제

Assume this setup:

interface IRepo 
{ 
  IEnumerable<Project> GetAllProjects();
}

class RavenRepo : IRepo
{
  IEnumerable<Project> GetAllProjects()
  {
     return session.query<Project>();
  }
}

class ApplicationService
{
  IRepo repo;
  public IEnumerable<Project> GetProjectsOrderedBySomething()
  {
    return repo.GetAllProjects().OrderBy(...);
  } 
}

This works fine, but I would like to add paging, all the way back to the Repo. If I just add it to GetAllProjects, the OrderBy wont work. I see three options:

  1. Add a new method for every single new ordering.
  2. Return IQueryable.
  3. Pass a list of keySelectors.

I don't like the idea of deferring execution from outside the repository, but I guess option 2 is the most useful apart from that? Also, this puts the burden (and responsibility) of paging on the service, meaning that someone might miss the requirement to use paging.

도움이 되었습니까?

해결책

As you found out, this is a pretty bad idea. See here for more details: http://www.wekeroad.com/2014/03/04/repositories-and-unitofwork-are-not-a-good-idea/

But, in general, don't use repositories with RavenDB.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top