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

I am using Ninject 2.2 and I am trying to set a binding for an open generic that takes two type arguments. According to this answer by qes, the correct syntax for binding IRepository<T> to Repository<T> is as follows:

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

The above syntax works fine if the IRepository accepts only one type argument, but breaks if it takes more (gives a compile-time error Using the generic type 'Repository<T,U>' requires 2 type arguments .)

How can I bind IRepository<T,U> to Repository<T,U> ?

Thank.

+21
c # ninject-2
Jul 19 2018-11-11T00:
source share
1 answer
 Bind(typeof(IRepository<,>)).To(typeof(Repository<,>)); 

Try it....

+39
Jul 19 2018-11-11T00:
source share



All Articles