using Microsoft.Extensions.Caching.Memory; namespace MesaFabApproval.API.Services; public interface ICustomerService { Task> GetCustomerNames(); } public class CustomerService : ICustomerService { private readonly ILogger _logger; private readonly IDalService _dalService; private readonly IMemoryCache _cache; public CustomerService(ILogger logger, IDalService dalService, IMemoryCache cache) { _logger = logger ?? throw new ArgumentNullException("ILogger not injected"); _dalService = dalService ?? throw new ArgumentNullException("IDalService not injected"); _cache = cache ?? throw new ArgumentNullException("IMemoryCache not injected"); } public async Task> GetCustomerNames() { try { _logger.LogInformation("Attempting to get customer names"); IEnumerable? customerNames = _cache.Get>("allCustomerNames"); if (customerNames is null) { string sql = "select ProductFamily from ProductFamilies;"; customerNames = (await _dalService.QueryAsync(sql)).ToList(); } return customerNames; } catch (Exception ex) { _logger.LogError($"Unable to get customer names, because {ex.Message}"); throw; } } }