Код: Выделить всё
public class CarFactory : ICarFactory
{
private const string carKey = "MyCarKey";
private readonly ICarDetailsRepository _carRepo;
private readonly ICachingService _cachingService;
public CarFactory(ICarDetailsRepository carRepo, ICachingService cachingService)
{
_carRepo = carRepo;
_cachingService = cachingService;
}
public async Task GetCarDetailsAsync(Guid carId)
{
return await _cachingService.GetOrCreateAsync(carId, carKey, async cancel =>
{
return await GetCarDetailsByCarIdAsync(carId, cancel);
});
}
private async Task GetCarDetailsByCarIdAsync(Guid carId, CancellationToken token)
{
return await _carRepo.GetCarDetailsAsync(carId, token);
}
}
Код: Выделить всё
public async Task GetOrCreateAsync(Guid id, string key, Func funcToGetItem)
{
return await _hybridCache.GetOrCreateAsync(CreateKeyWithPrefix(id, key), funcToGetItem);
}
< /code>
Пока я попробовал следующее: < /p>
_cachingServiceMock
.Setup(csm => csm.GetOrCreateAsync(carId, It.IsAny(), It.IsAny()))
.Callback(async (id, key, func) => await func.Invoke(default));
Подробнее здесь: https://stackoverflow.com/questions/796 ... ybridcache