注册开放通用服务时错误地要求我提供类型参数

Cap*_*ard 3 c# dependency-injection asp.net-core

我有一个通用存储库,它采用通用 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);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试在 Startup.cs 中注册此服务时,编译器会要求我提供类型参数,而根据此链接我不应该收到此错误?

services.AddScoped(typeof(IDataRepo<>), typeof(DataRepo<>));
Run Code Online (Sandbox Code Playgroud)

我得到的错误是这样的;

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

有人可以指出我正确的方向吗?

Nko*_*osi 7

由于您有多个通用参数,因此需要在通用参数中包含逗号

services.AddScoped(typeof(IDataRepo<,>), typeof(DataRepo<,>));
Run Code Online (Sandbox Code Playgroud)

正确表示所涉及的类型需要多少个泛型参数