2
に汎用サービスを追加:は以下で、asp.netコアDIでasp.netのコアDI
public interface IRepository<T> where T:class {}
public class Repository<T> : IRepository<T> where T:class {}
私は私のsevicesを登録するには、次の手順を実行します:
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
が、今を私は以下のようなサービスを提供しています:
public interface IContextProvider<T1,T2> {}
public class ContextProviderOne<T2> : IContextProvider<ContextClass1,T2> { }
public class ContextProviderTwo<T2> : IContextProvider<ContextClass2,T2> { }
私のサービスをDIにどのように追加しますか?
を 'services.AddScoped(typeof演算(IRepository <>)、typeof演算(IRepository <>))がされる方法;' 'IRepository <、動作するようになっ>'することはできませんインスタンス化された、それは具体的なクラスではなくインターフェースです。 – Tseng
次の登録は組み込みコンテナでは機能しません。 'services.AddScoped(typeof(IContextProvider <,>)、typeof(ContextProviderOne <>)); services.AddScoped(typeof(IContextProvider <,>)、typeof(ContextProviderTwo <>)); '? – Steven
@Tseng:それは明らかにタイプミスです。 – Steven