[英]Ninject: How to bind an open generic with more than one type argument?
我正在使用 Ninject 2.2,我正在尝试为一个开放泛型设置一个绑定,该泛型采用两种类型 arguments。 根据 qes 的这个答案,将IRepository<T>
绑定到Repository<T>
的正确语法是这样的:
Bind(typeof(IRepository<>)).To(typeof(Repository<>));
如果IRepository
仅采用一个类型参数,则上述语法完美运行,但如果它需要更多则中断(给出Using the generic type 'Repository<T,U>' requires 2 type arguments
编译时错误。)
如何将IRepository<T,U>
绑定到Repository<T,U>
?
谢谢。
Bind(typeof(IRepository<,>)).To(typeof(Repository<,>));
试试看……
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.