IAsyncQueryableExecuter ,IAsyncQueryableProvider
利用这俩个 api 实现在仓储层实现和数据库完全解耦,IAsyncQueryableProvider 的实现者要靠具体 的数据库提供程序 IAsyncQueryableProvider 多个对象 会注入 IAsyncQueryableExecuter 类的构造 函数
如下的伪代码说明了
public class PersonAppService : ApplicationService
{
private readonly IRepository<Person, Guid> _personRepository;
private readonly IAsyncQueryableExecuter _asyncExecuter;
public PersonAppService(IRepository<Person, Guid> personRepository, IAsyncQueryableExecuter asyncExecuter)
{
_personRepository = personRepository;
_asyncExecuter = asyncExecuter;
}
public async Task CreateAsync(CreatePersonDto input)
{
var person = new Person(input.Name);
await _personRepository.InsertAsync(person);
}
public async Task<int> GetCountAsync(string filter)
{
var queryable = _personRepository.Where(p => p.Name.Contains(filter));
return await _asyncExecuter.CountAsync(queryable);
}
}
👍🎉🎊