我正在使用 Ninject 2.2,我正在尝试为一个采用两个类型参数的开放泛型设置绑定(bind)。根据这个answer通过 qes,绑定(bind)的正确语法 IRepository<T>
至 Repository<T>
这是:
Bind(typeof(IRepository<>)).To(typeof(Repository<>));
如果 IRepository
,上述语法将完美运行只接受一个类型参数,但如果需要更多类型参数则中断(给出 Using the generic type 'Repository<T,U>' requires 2 type arguments
编译时错误。)
如何绑定(bind) IRepository<T,U>
至 Repository<T,U>
?
谢谢。
最佳答案
Bind(typeof(IRepository<,>)).To(typeof(Repository<,>));
试试看....
关于c# - 输入 : How to bind an open generic with more than one type argument?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6740992/