I have a Generic Repository which takes a Generic DbContext and a Generic Model,
The Code I have is just a basic Generic Repository like so;
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);
}
}
when I try to register this Service in Startup.cs, the compiler asks me for type arguments when according to this link I shouldn't be getting this error?
services.AddScoped(typeof(IDataRepo<>), typeof(DataRepo<>));
The Error I get is this;
CS0305 Using the generic type 'IDataRepo' requires 2 type arguments
Could someone point me in the right direction with this please?
Because you have multiple generic arguments, you will need to include a comma in the generic arguments
services.AddScoped(typeof(IDataRepo<,>), typeof(DataRepo<,>));
to properly represent how many generic arguments are needed for the types involved
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.