using Microsoft.Extensions.DependencyInjection; using Seyounth.Hyosung.Data.Entities; using Seyounth.Hyosung.Data.Repositories; using SqlSugar; namespace Seyounth.Hyosung.Data.Services; public class DictService : IDictService { private readonly IRepository _repository; private readonly List _cache; public DictService(IServiceProvider provider) { _repository = provider.CreateScope() .ServiceProvider.GetRequiredService>(); //_repository = provider.GetService>(); _cache = _repository.GetList(); } public async Task GetKeyAsync(string type, string name) { return _cache.FirstOrDefault(d => d.Type == type && d.Value == name)?.Key ?? ""; } public async Task> GetDictsByTypeAsync(string type) { return _cache.Where(d => d.Type == type).ToList(); } public async Task SetValue(string type, string key, string value) { await _repository.CopyNew().AsUpdateable() .Where(x => x.Type == type && x.Key == key).SetColumns(x => x.Value, value).ExecuteCommandAsync(); ; } public async Task GetValue(string type, string key) { var dict = await _repository.CopyNew().GetFirstAsync(x => x.Type == type && x.Key == key); return dict.Value; } }