【发布时间】:2016-09-04 18:37:24
【问题描述】:
我有以下存储库类:
public class TestRepository : Repository<Test>
{
private TestContext _context;
public TestRepository(TestContext context) : base(context)
{
_context = context;
}
}
public abstract class Repository<T> : IRepository<T> where T : Entity
{
private TestContext _context;
public Repository(TestContext context)
{
_context = context;
}
...
}
public interface IRepository<T>
{
...
}
如何在我的Startup.cs 中实现 ASP.NET Core 中的依赖注入?
我是这样实现的:
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
然后我得到以下错误:
无法实例化实现类型“Test.Domain.Repository
1[T]' for service type 'Test.Domain.IRepository1[T]”。
【问题讨论】:
标签: c# generics dependency-injection asp.net-core