这是一个基础界面:
public interface IBaseDataService<TPage> : IDisposable where TPage : PageBase
{
Task<TPage> GetBySlug(string slug,
CancellationToken cancellationToken = default(CancellationToken));
}
并在此处扩展:
public interface IReadDataService : IBaseDataService<MyPage>
{
}
这是界面实现:
public class MyDataService : IMyDataService
{
private readonly MyDbContext dbcontext;
public MyDataService (MyDbContext dbcontext)
{
this.dbcontext = dbcontext;
}
public async Task<MyPage> GetBySlug(string slug,
CancellationToken cancellationToken = default(CancellationToken))
{
....
}
}
最后我将实现添加到DI:
services.AddScoped<IMyDataService, MyDataService>();
当我在控制器中使用它时,在界面中找到GetBySlug
。
答案 0 :(得分:0)
我添加了两次实现并且工作正常。
services.AddScoped<IMyDataService, MyDataService>();
services.AddScoped<IBaseDataService<MyPage>, MyDataService>();