Common.cs 1.1 KB

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