2011-10-10 2 views
3

내 IService에는 IRepository의 모든 것과 특정 작업이 더 있다고 할 수 있습니까? IRepository의 모든 작업이 IService도 있습니다IService는 IRepository를 확장합니까?

public interface IRepository<T> 
{ 
    T Add(T Entity); 
    T Remove(T Entity); 
    IQueryable<T> GetAll(); 
} 

public interface IUserService 
{ 

    //All operations IRepository 
    User Add(User Entity); 
    User Remove(User Entity); 
    IQueryable<User> GetAll(); 

    //Others specific operations 
    bool Approve(User usr); 
} 

참고 :

다음은 코드입니다.

이 정보가 맞습니까? 또 다른 옵션이 될 것

public interface IUserService : IRepository<User> 
{ 
    bool Approve(User usr); 
} 

:

그렇다면,이 같은 뭔가를 더 좋을 거라 내가 속성으로 저장소를 넣어

public interface IUserService 
{ 
    IRepository<User> Repository { get; } 

    //All operations IRepository 
    User Add(User Entity); 
    User Remove(User Entity); 
    IQueryable<User> GetAll(); 

    //Others specific operations 
    bool Approve(User usr); 
} 

public class UserService : IUserService 
{ 
    private readonly IRepository<User> _repository; 
    public IRepository<User> Repository 
    { 
     get 
     { 
      return _repository; 
     } 
    } 

    //Others specific operations 
    public bool Approve(User usr) { ... } 
} 

참고하고, 내 서비스 수업에서이 물건을 드러내고있어.

그래서 저장소에 개체를 추가, 제거 또는 가져와야하는 경우이 속성을 통해 액세스 할 수 있습니다.

귀하의 의견은 무엇입니까? 이 작업을 올바르게 했습니까?

+0

는 플래그되는 질문을 방지하고 ... 모든 대답은 동등하게 유효한 경우 가능한 제거, 주관적인 질문을 피하려면 : "좋아하는 무엇 ______" 당신의 대답은 질문과 함께 제공되며, 당신은 더 많은 답변을 기대합니다 : "나는 ______에 ______을 사용하는데 무엇을 사용합니까?" 해결할 실제 문제는 없습니다. "다른 사람들이 내가하는 것처럼 느낀다면 궁금합니다." 우리는 개방적이고 가상적인 질문을 받고 있습니다. : "______이 (가) 일어난다면 어떨까요?" 질문으로 가장 한 호언 장담이다. "______는 빤다. 맞다." – cadrell0

+0

어쩌면 질문하는 법을 모르겠습니다. 내가 알고 싶은 것은 어떻게 내 저장소의 메소드를 노출 시키는가입니다. 내 서비스에서 속성으로 속성을 노출하거나 저장소의 메서드에 액세스하는 메서드를 만드는 경우 – ridermansb

+0

@ cadrell0 : 그는 3 가지 가능한 방법을 제시하고 주관적인 이유가 아니라 객관적인 이유를 위해 그가 사용해야하는 질문을했습니다. –

답변

4

당신은 이미이 문제를 직접 해결했지만 어쨌든 의견을 제시 할 것입니다.
두 번째 예 :

public interface IUserService : IRepository<User> 
{ 
    bool Approve(User usr); 
} 

당신이 무엇을 사용해야 - 그것은 좋은 깨끗합니다. 첫 번째 예제에서 IUserService에 포함 된 대부분의 내용은 완전히 중복되었지만 IUserService이 실제로 추가하는 것은 bool Approve(User usr)입니다. 당신이 볼 수 있듯이

public class UserService : IUserService 
{ 
    public bool Approve(User usr) 
    { 
     throw new NotImplementedException(); 
    } 

    public User Add(User Entity) 
    { 
     throw new NotImplementedException(); 
    } 

    public User Remove(User Entity) 
    { 
     throw new NotImplementedException(); 
    } 

    public IQueryable<User> GetAll() 
    { 
     throw new NotImplementedException(); 
    } 
} 

public class User { } 

public interface IRepository<T> 
{ 
    T Add(T Entity); 
    T Remove(T Entity); 
    IQueryable<T> GetAll(); 
} 

public interface IUserService : IRepository<User> 
{ 
    bool Approve(User usr); 
} 

, 종류가 모두 제대로 설치 : 당신은 또한 당신의 두 번째 예제를 사용하는 경우, 때 UserService를 추가하고 다음으로 끝날 자동으로 IUserService을 구현하는 비주얼 스튜디오를 얻을 것을 발견 할 것이다 당신을 위해서, IUserService에서 여분의 것을 할 필요없이.

+0

좋아, 나는 재산으로 저장소를 노출 생각했다; 어떻게 생각해? – ridermansb