DIとコンストラクターインジェクションに次のジェネリックリポジトリインターフェイスを使用しようとしています。
public interface IRepository<TEntity> : IDisposable where TEntity : class
問題は、インターフェイスのインスタンスを定義するために、次のようなクラスタイプを提供する必要があることです。
private IRepository<Person> _personRepository;
これに関する問題は、DIを使用している場合(およびUnity for IoCフレームワークを使用している場合)、コンストラクターで複数のインスタンスを定義して、次のように操作する必要のあるすべてのリポジトリインターフェイスを取得する必要があります。
public MyClass(IRepository<Person> personRepository,
IRepository<Orders> ordersRepository,
IRepository<Items> itemsRepository,
IRepository<Locations> locationsRepository)
{
_personRepository = personRepository;
_OrdersRepository = ordersRepository;
_itemsRepository = itemsRepository;
_locationsRepository = locationsRepository;
}
質問:
- これでいい?
- そうでなければ、私はこの概念にどこで迷子になっていますか?
- これが適切であるとしても、インターフェイスを具象型に登録するUnityのポイントは何ですか?ジェネリックリポジトリが私に宣言を強制したので、私はすでにそれをしました。
私のためにこれを片付けるのを手伝ってください、そして私はあなたのすべての助けに感謝します!