アプリケーションで Dapper ORM を使用しています。Dapper のどの機能がこのアプリケーションで使用されているかを一目でわかるように、Dapper のメソッドとのインターフェイスを作成しました。これを実装することで、他の ORM に簡単に置き換えることができます。
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
}
}
DAL レイヤーから:
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 を「静的」メソッドで「静的」に変更することをお勧めします。そうすることでパフォーマンスが向上するかどうかを知りたいです。
また、この設計を改善するための入力を歓迎します。