5
オブジェクトごとに特定のリポジトリではなく、一般的なリポジトリを作成する利点は何ですか?
ASP.NET MVCアプリケーションを開発しており、現在、リポジトリ/サービスクラスを構築しています。すべてのリポジトリが実装する汎用のIRepositoryインターフェイスを作成することには、各リポジトリが独自のインターフェイスとメソッドのセットを持っているのに対して、大きな利点があるのかと思います。 たとえば、汎用のIRepositoryインターフェイスは次のようになります(この回答から取得)。 public interface IRepository : IDisposable { T[] GetAll<T>(); T[] GetAll<T>(Expression<Func<T, bool>> filter); T GetSingle<T>(Expression<Func<T, bool>> filter); T GetSingle<T>(Expression<Func<T, bool>> filter, List<Expression<Func<T, object>>> subSelectors); void Delete<T>(T entity); void Add<T>(T entity); int SaveChanges(); DbTransaction BeginTransaction(); } 各リポジトリはこのインターフェースを実装します、例えば: CustomerRepository:IRepository ProductRepository:IRepository 等 以前のプロジェクトで従った代替案は次のとおりです。 public interface IInvoiceRepository : IDisposable { EntityCollection<InvoiceEntity> GetAllInvoices(int …