응용 프로그램에서 Dapper ORM을 사용하고 있습니다. Dapper의 기능이이 응용 프로그램에서 사용되고 있고 그것을 구현하여 다른 ORM으로 쉽게 대체 할 수있는 사람을 위해 Dapper 메서드로 인터페이스를 만들었습니다. DAL 레이어에서인터페이스 기반 접근 방식 또는 정적 도우미 메서드 사용
public interface IDapperRepository
{
IEnumerable<T> GetAll<T>(string query, object cmdParams = null, CommandType cmdType = CommandType.Text) where T : class;
T GetById<T>(string query, object cmdParams = null, CommandType cmdType = CommandType.Text) where T : class;
}
class DapperRepository : IDapperRepository
{
public IEnumerable<T> GetAll<T>(string query, object cmdParams = null, CommandType cmdType = CommandType.Text) where T : class
{
//implementation
}
public T GetById<T>(string query, object cmdParams = null, CommandType cmdType = CommandType.Text) where T : class
{
//implementation
}
}
: 사용자 목록 페이지에서
public class UserRep : IUserRep
{
private readonly IDapperRepository _iDapperRepository;
public UserRep()
{
_iDapperRepository = new DapperRepository();
}
public IEnumerable<UserBO> GetAll()
{
return _iDapperRepository.GetAll<UserBO>("select * from users");
}
//Other methods
}
, _iUserRep.GetAll()는 컨트롤러에서 호출됩니다.
위의 코드에서 _iUserRep.GetAll() 또는 저장소 클래스의 다른 메서드를 호출하면 DapperRepository 클래스가 인스턴스화됩니다. 내 질문은 DapperRepository 클래스에만 유틸리티 메서드가 있기 때문에 IDapperRepository를 제거하고 DapperRepository를 "정적"메서드로 "정적"메서드로 수정하여 인스턴스화하지 않고 메서드를 호출 할 수 있도록하는 것이 좋습니다. 그렇게함으로써 성능 향상이 있는지 여부를 알고 싶습니다.
또한이 디자인을 개선하기위한 모든 의견을 환영합니다.
* controller *를 언급했는데 ASP.MVC 응용 프로그램에서 일하고 있습니까? – jwaliszko
예, MVC 응용 프로그램입니다. 그것은 설계상의 문제가 더 많기 때문에 그것에 대해 많이 언급하지 않았습니다. – Sunny