CommonConfig.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Database.Database;
  7. using log4net;
  8. namespace Common.Singleton
  9. {
  10. public class CommonConfig
  11. {
  12. List<Config>? configs;
  13. private CommonConfig() { }
  14. private static CommonConfig? instance = null;
  15. public static CommonConfig Instance
  16. {
  17. get
  18. {
  19. if (instance == null)
  20. {
  21. instance = new CommonConfig();
  22. }
  23. return instance;
  24. }
  25. }
  26. public void InitConfig(ILog log, ModelContext dbContext)
  27. {
  28. log.Info("INIT config");
  29. if (configs == null || configs.Count == 0)
  30. {
  31. configs = dbContext.Configs.ToList();
  32. log.Info("Total config: " + configs.Count);
  33. }
  34. }
  35. public List<Config>? GetConfig(string name)
  36. {
  37. if (configs != null && configs.Count > 0)
  38. {
  39. return configs.FindAll(x => x.ParamName == name);
  40. }
  41. return null;
  42. }
  43. public List<Config>? GetConfig(List<string> nameList)
  44. {
  45. if (configs != null && configs.Count > 0)
  46. {
  47. return configs.FindAll(x => nameList.Contains(x.ParamName));
  48. }
  49. return null;
  50. }
  51. }
  52. }