| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Database.Database;
- using log4net;
- namespace Common.Singleton
- {
- public class CommonConfig
- {
- List<Config>? configs;
- private CommonConfig() { }
- private static CommonConfig? instance = null;
- public static CommonConfig Instance
- {
- get
- {
- if (instance == null)
- {
- instance = new CommonConfig();
- }
- return instance;
- }
- }
- public void InitConfig(ILog log, ModelContext dbContext)
- {
- log.Info("INIT config");
- if (configs == null || configs.Count == 0)
- {
- configs = dbContext.Configs.ToList();
- log.Info("Total config: " + configs.Count);
- }
- }
- public List<Config>? GetConfig(string name)
- {
- if (configs != null && configs.Count > 0)
- {
- return configs.FindAll(x => x.ParamName == name);
- }
- return null;
- }
- public List<Config>? GetConfig(List<string> nameList)
- {
- if (configs != null && configs.Count > 0)
- {
- return configs.FindAll(x => nameList.Contains(x.ParamName));
- }
- return null;
- }
- }
- }
|