C# 注册打开的泛型服务会错误地要求我输入类型参数

C# 注册打开的泛型服务会错误地要求我输入类型参数,c#,asp.net-core,dependency-injection,C#,Asp.net Core,Dependency Injection,我有一个通用存储库,它采用通用DbContext和通用模型 我的代码只是一个基本的通用存储库,就像这样 public class DataRepo<T,M> : IDataRepo<T,M> where T:DbContext where M :class { private readonly T _Context; private readonly M _Model; public DataRepo(T Context, M model)

我有一个通用存储库,它采用通用DbContext和通用模型

我的代码只是一个基本的通用存储库,就像这样

public class DataRepo<T,M> : IDataRepo<T,M> where T:DbContext where M :class
{
    private readonly T _Context;
    private readonly M _Model;


    public DataRepo(T Context, M model)
    {
        _Context = Context;
        _Model = model;
    }
    public void Delete()
    {
       _Context.Remove(_Model);
    }

    public async Task<IEnumerable<T>> GetAll()
    {
        var results = await _Context.Set<T>().AsQueryable().AsNoTracking().ToListAsync();

        return results;
    }

    public T GetSingleByID(int ID)
    {
        return _Context.Find<T>(ID);            
    }

    public void InsertBulkItems(ICollection<M> dataModels)
    {
        _Context.AddRange(dataModels);
    }

    public void InsertSingleItem()
    {
        _Context.Add(_Model);
    }

    public void UpdateItem()
    {
        _Context.Update(_Model);
    }
}
公共类DataRepo:IDataRepo其中T:DbContext其中M:class
{
私有只读T_上下文;
私有只读M_模型;
公共数据报告(T上下文,M模型)
{
_上下文=上下文;
_模型=模型;
}
公共作废删除()
{
_删除(_模型);
}
公共异步任务GetAll()
{
var results=await_Context.Set().AsQueryable().AsNoTracking().toListSync();
返回结果;
}
公共T GetSingleByID(int ID)
{
返回_Context.Find(ID);
}
公共void InsertBulkItems(ICollection数据模型)
{
_AddRange(数据模型);
}
public void InsertSingleItem()
{
_添加(_模型);
}
public void UpdateItem()
{
_更新(_模型);
}
}
当我尝试在Startup.cs中注册此服务时,编译器会要求我输入类型参数,而根据我不应该得到此错误

services.AddScoped(typeof(IDataRepo<>), typeof(DataRepo<>));
services.addScope(typeof(IDataRepo)、typeof(DataRepo));
我得到的错误是:

CS0305使用泛型类型“IDataRepo”需要2个类型参数


有人能给我指出正确的方向吗?

因为你有多个泛型参数,你需要在泛型参数中包含一个逗号

services.AddScoped(typeof(IDataRepo<,>), typeof(DataRepo<,>));
services.addScope(typeof(IDataRepo)、typeof(DataRepo));
正确表示所涉及类型需要多少泛型参数