Setting.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. namespace bitforum.Models
  2. {
  3. public static class Setting
  4. {
  5. public static AppConfig AppConfig { get; private set; } = new();
  6. public static ConnectionStrings ConnectionStrings { get; private set; } = new();
  7. public static Redis Redis { get; private set; } = new();
  8. public static Smtp Smtp { get; private set; } = new();
  9. public static Jwt Jwt { get; private set; } = new();
  10. static Setting()
  11. {
  12. var appSettings = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: false, reloadOnChange: true).Build();
  13. appSettings.GetSection("AppConfig").Bind(AppConfig);
  14. appSettings.GetSection("ConnectionStrings").Bind(ConnectionStrings);
  15. appSettings.GetSection("Redis").Bind(Redis);
  16. appSettings.GetSection("Smtp").Bind(Smtp);
  17. appSettings.GetSection("JWT").Bind(Jwt);
  18. }
  19. }
  20. public class AppConfig
  21. {
  22. public string AppName { get; set; } = null!;
  23. public string AppVersion { get; set; } = null!;
  24. public string BaseURL { get; set; } = null!;
  25. }
  26. public class ConnectionStrings
  27. {
  28. public string DefaultConnection { get; set; } = null!;
  29. }
  30. public class Redis
  31. {
  32. public string Host { get; set; } = null!;
  33. public int Port { get; set; }
  34. public string Password { get; set; } = null!;
  35. }
  36. public class Smtp
  37. {
  38. public string Server { get; set; } = null!;
  39. public int Port { get; set; }
  40. public bool EnableSSL { get; set; }
  41. public string Username { get; set; } = null!;
  42. public string Password { get; set; } = null!;
  43. public string FromEmail { get; set; } = null!;
  44. public string FromName { get; set; } = null!;
  45. }
  46. public class Jwt
  47. {
  48. public string SecretKey { get; set; } = null!;
  49. public string Issuer { get; set; } = null!;
  50. public string Audience { get; set; } = null!;
  51. public int AccessTokenExpiration { get; set; }
  52. public int RefreshTokenExpiration { get; set; }
  53. }
  54. }