title: c# pass class inheritance from generic abstract class in generic param
body: <p>I have this tree interfaces/classes</p>
  
  <blockquote>
    <p>BaseRepository.cs</p>
  </blockquote>
  
  <pre><code>abstract public class BaseRepository&lt;Entity&gt; : IRepository
      where Entity : BaseEntity, new()
  {
      public virtual IList&lt;Entity&gt; FindAll()
      {
          ...
          return list;
      }
  }
  </code></pre>
  
  <p>Try to automatize the Get, Update, Insert webapi creation with generics</p>
  
  <blockquote>
    <p>BaseApiController</p>
  </blockquote>
  
  <pre><code>public class BaseEntityApiController&lt;Repository&gt; : ApiController
      where Repository : BaseRepository&lt;BaseEntity&gt;, new()
  {
      Repository repository = new Repository();
  
      public IList&lt;BaseEntity&gt; Get()
      {
           return repository.FindAll();
      }
  
  }
  </code></pre>
  
  <blockquote>
    <p>UserRepository</p>
  </blockquote>
  
  <pre><code>public class UserRepository : BaseRepository&lt;User&gt;
  {  
  }
  </code></pre>
  
  <p>I created a new controller that inheritance from BaseApiController passing the UserRepository:</p>
  
  <blockquote>
    <p>UserController</p>
  </blockquote>
  
  <pre><code>public class UserController : BaseApiController&lt;UserRepository&gt;
  {
  }
  </code></pre>
  
  <p>I receive this error:</p>
  
  <pre><code>Project.UserRepository cannot be used as type parameters 'Repository' in the generic type or method 'BaseApiController&lt;Repository&gt;'. There is no implicit reference conversion from Project.UserRepository to Project BaseRepository&lt;Project.BaseEntity&gt;.
  </code></pre>
  
  <p>How can i pass my UserRepository with generic type to my BaseApiController to automatize the creation of Api used in all controllers?</p>