title: How to bind Generic-type interfaces in Ninject
body: <p>I'm fairly new to Ninject, and found myself stumbling when I came to implement a generic repository pattern.  I want to bind a dependency <strong>IRepository&lt;IEntityType></strong> to a class <strong>ConcreteRepository&lt;EntityType></strong> where ConcreteRepository&lt;T> implements IRepository&lt;T> and EntityType implements IEntityType.  I tried this:</p>
  
  <pre><code>kernel.Bind&lt;IRepository&lt;IEntityType&gt;&gt;().To&lt;ConcreteRepository&lt;EntityType&gt;&gt;();
  </code></pre>
  
  <p>...but Ninject won't take that because it doesn't know or care that EntityType implements IEntityType.  How can I go about binding this dependency?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This is the error I'm getting:</p>
  
  <blockquote>
    <p>Error 3   The type 'ICM.Dependency.Repository.ConcreteRepository' cannot be used as type parameter 'TImplementation' in the generic type or method 'Ninject.Syntax.IBindingToSyntax.To()'. There is no implicit reference conversion from 'ConcreteRepository&lt;EntityType>' to 'IRepository&lt;IEntityType>'.   </p>
  </blockquote>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>I still don't quite understand why my binding doesn't work, but evidently I was using generics incorrectly there.  As such the solution doesn't really relate to NInject.  I ended specifying the ConcreteRepository to explicitly connect IEntityType with TEntityType:</p>
  
  <pre><code>public class ConcreteRepository&lt;TInterface, TEntity&gt; : IRepository&lt;TInterface&gt; where TEntity : TInterface { ... }
  </code></pre>
  
  <p>Then the injection can be written as follows:</p>
  
  <pre><code>kernel.Bind&lt;IRepository&lt;IEntityType&gt;&gt;().To&lt;ConcreteRepository&lt;IEntityType,EntityType&gt;&gt;()
  </code></pre>