내 충고는 핵심 기본 방법 (Find
, Save
, Delete
등)이있는 GenericRepository<T>
을 만드는 것입니다.
예 :
public abstract class GenericRepository<T> : IRepository<T> where T : class
{
public T FindSingle(Expression<Func<T,bool>> predicate) { .. };
public IQueryable<T> Find() { .. };
public void Delete(T entity) { .. };
}
그런 다음 전문 방법을 만들기 위해, 일반 하나에서 상속 특정 저장소를 만들 수 있습니다.
예 :
public class EmployeeRepository : GenericRepository<Employee>, IRepository<Employee>
{
public Employee FindByLastName(string lastName)
{
return FindSingle(emp => emp.LastName == lastName);
}
public ICollection<Employee> FindAllManagers()
{
return Find().Where(emp => emp.Type == "Manager").ToList();
}
// other methods...
}
당신이 당신의 저장소에서 공통 코드를 복제하지 의미합니다.
네, 다른 대안은 GenericRepository<T>
에서 작동하는 서비스를 갖는 것입니다. 이는 서비스가 (본질적으로) 전문화 된 저장소라는 것을 의미합니다.
서비스 계층 또는 전문 리포 지 토리를 원할 경우 우선 순위에 관한 문제입니다.
흠 ... 나는 당신에 대해 생각해 보았습니다. 감사!! – AndreMiranda