How to inject dependencies of generics in ASP.NET Core
<p>I have following repository classes:</p>

<pre><code>public class TestRepository : Repository&lt;Test&gt;
{
    private TestContext _context;

    public TestRepository(TestContext context) : base(context)
    {
        _context = context;
    }
}

public abstract class Repository&lt;T&gt; : IRepository&lt;T&gt; where T : Entity
{
    private TestContext _context;

    public Repository(TestContext context)
    {
        _context = context;
    }
    ...
}

public interface IRepository&lt;T&gt;    
{
    ...
}
</code></pre>

<p>How do I implement the dependency injection in ASP.NET Core in my <code>Startup.cs</code>?</p>

<p>I implemented it like this:</p>

<pre><code>services.AddScoped(typeof(IRepository&lt;&gt;), typeof(Repository&lt;&gt;));
</code></pre>

<p>But then I get following error: </p>

<blockquote>
  <p>Cannot instantiate implementation type 'Test.Domain.Repository<code>1[T]'
  for service type 'Test.Domain.IRepository</code>1[T]'.</p>
</blockquote>