Ninject: How to bind an open generic with more than one type argument?

馋奶兔 提交于 2019-12-03 06:45:59

问题


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.


回答1:


Bind(typeof(IRepository<,>)).To(typeof(Repository<,>));

Try that....



来源:https://stackoverflow.com/questions/6740992/ninject-how-to-bind-an-open-generic-with-more-than-one-type-argument

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!