Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 929
Daniel Liuzzi Avatar asked Jul 19 '11 00:07

Daniel Liuzzi


1 Answers

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

Try that....

like image 97
BFree Avatar answered Oct 08 '22 08:10

BFree