Common.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Text.Json;
  2. using bitforum.Constants;
  3. using bitforum.Models;
  4. namespace bitforum.Middleware
  5. {
  6. // 환경변수 구조
  7. public class AppConfig
  8. {
  9. public string AppName { get; set; }
  10. public string AppVersion { get; set; }
  11. }
  12. public class Common
  13. {
  14. private readonly RequestDelegate _next;
  15. private readonly IConfiguration _configuration;
  16. public Common(RequestDelegate next, IConfiguration configuration)
  17. {
  18. _next = next;
  19. _configuration = configuration;
  20. }
  21. public async Task InvokeAsync(HttpContext context)
  22. {
  23. AppConfig? appConfig = null;
  24. try
  25. {
  26. appConfig = _configuration.GetSection("AppConfig").Get<AppConfig>(); ;
  27. }
  28. catch (JsonException ex)
  29. {
  30. Console.WriteLine($"JSON Parsing Error: {ex.Message}");
  31. }
  32. context.Items["layoutViewModel"] = new LayoutViewModel
  33. {
  34. // 환경 변수 가져오기
  35. AppConfig = appConfig,
  36. // 메뉴 데이터 가져오기
  37. Menus = MenuData.GetMenus()
  38. };
  39. await _next(context);
  40. }
  41. }
  42. }