[英]Ninject binding with two generic parameters in types
我有這個界面:
public interface IRepository<TDomain, TBusiness>
where TDomain : class
where TBusiness : class
{...}
而這個類:
public class Repository<TDomain, TBusiness> : IRepository<TDomain, TBusiness>
where TDomain : class
where TBusiness : class
{...}
當我用 ninject 綁定時,類似於:
Kernel.Bind(typeof(IRepository<>))
.To(typeof(Repository<>))
.InRequestScope();
並出現錯誤“...中的類型參數數量不正確”。 當我只有一個泛型類型時,一切正常。 有沒有人解決這個問題的解決方案?
這與 Ninject 無關,您得到的錯誤是 C# 編譯器錯誤。 這是因為使用兩個泛型參數指定類型的正確方法如下:
typeof(IRepository<,>)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.