public IConfig Get(Type implementType) { var descriptor = GetDescriptor(m => m.ImplementType == implementType); if (descriptor.Instance == null) { var json = _storageProvider.GetJson(descriptor.Type, descriptor.Code).Result; if (json.IsNull()) { descriptor.Instance = (IConfig)Activator.CreateInstance(implementType); if (descriptor.Type == ConfigType.Library) { var section = _cfg.GetSection(descriptor.Code); if (section != null) { section.Bind(descriptor.Instance); } } } else { descriptor.Instance = (IConfig)JsonConvert.DeserializeObject(json, implementType); } } return(descriptor.Instance); }
private IConfig Get(ConfigDescriptor descriptor) { var key = _redisHelper.GetKey($"{CACHE_KEY}:{descriptor.Type.ToString().ToUpper()}:{descriptor.Code.ToUpper()}"); var cache = _redisHelper.Db.StringGetAsync(key).Result; if (cache.HasValue) { return((IConfig)_redisSerializer.Deserialize(cache, descriptor.ImplementType)); } IConfig config; var json = _storageProvider.GetJson(descriptor.Type, descriptor.Code).Result; if (json.IsNull()) { config = (IConfig)Activator.CreateInstance(descriptor.ImplementType); if (descriptor.Type == ConfigType.Library) { var section = _cfg.GetSection(descriptor.Code); if (section != null) { section.Bind(config); } } } else { config = (IConfig)JsonConvert.DeserializeObject(json, descriptor.ImplementType); } _redisHelper.Db.StringSetAsync(key, _redisSerializer.Serialize(config)).GetAwaiter().GetResult(); return(config); }