Ninject:如何绑定一个开放式泛型与多个类型参数? [英] Ninject: How to bind an open generic with more than one type argument?
问题描述
我使用Ninject 2.2,而我试图建立一个开放通用的带两个类型参数的绑定。根据这一通过QES回答,正确的语法来绑定 IRepository< T>
到库< T>
是这样的:
绑定(typeof运算(IRepository<>))至(typeof运算(库<>))。
以上语法完美的作品,如果 IRepository
需要只是一种说法,但休息,如果它需要更多(给出了一个使用泛型类型'仓库< T,U>'。需要2个类型参数
编译时错误)
我怎样才能绑定 IRepository< T,U>
到库< T,U>
?
感谢。
绑定(typeof运算(IRepository<,>))。为了(typeof运算(库<,>));
尝试了....
I'm using Ninject 2.2, and I'm trying to setup a binding for an open generic that takes two type arguments. According to this answer by qes, the correct syntax to bind IRepository<T>
to Repository<T>
is this:
Bind(typeof(IRepository<>)).To(typeof(Repository<>));
The above syntax works perfectly if IRepository
takes just one type argument, but breaks if it takes more (gives a Using the generic type 'Repository<T,U>' requires 2 type arguments
compile time error.)
How can I bind IRepository<T,U>
to Repository<T,U>
?
Thanks.
Bind(typeof(IRepository<,>)).To(typeof(Repository<,>));
Try that....
这篇关于Ninject:如何绑定一个开放式泛型与多个类型参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!