Ninject:如何绑定一个开放式泛型与多个类型参数? [英] Ninject: How to bind an open generic with more than one type argument?

查看:661
本文介绍了Ninject:如何绑定一个开放式泛型与多个类型参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆