Program.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Database.Database;
  2. using Kitty_Fall.Apis.Business.Game;
  3. using Kitty_Fall.Apis.Business.User;
  4. using log4net;
  5. using Microsoft.EntityFrameworkCore;
  6. using Kitty_Fall.Apis.Business;
  7. using System.Reflection;
  8. using System.Xml;
  9. // Use the server OS time zone, ignoring a process-level TZ override.
  10. // On Linux this uses /etc/localtime; configure the same zone inside a container.
  11. Environment.SetEnvironmentVariable("TZ", null);
  12. TimeZoneInfo.ClearCachedData();
  13. // Oracle session time is configured separately from the process/logging time zone.
  14. Environment.SetEnvironmentVariable("ORA_SDTZ", "+06:30");
  15. XmlDocument log4netConfig = new XmlDocument();
  16. log4netConfig.Load(File.OpenRead("log4net.config"));
  17. var repo = log4net.LogManager.CreateRepository(
  18. Assembly.GetEntryAssembly(),
  19. typeof(log4net.Repository.Hierarchy.Hierarchy)
  20. );
  21. log4net.Config.XmlConfigurator.Configure(repo, log4netConfig["log4net"]);
  22. LogManager.GetLogger(typeof(Program)).Info(
  23. $"API clock: local={DateTimeOffset.Now:O}, utc={DateTimeOffset.UtcNow:O}, timezone={TimeZoneInfo.Local.Id}");
  24. var builder = WebApplication.CreateBuilder(args);
  25. var oracleSessionTimeZone = builder.Configuration["OracleSessionTimeZone"];
  26. if (!string.IsNullOrWhiteSpace(oracleSessionTimeZone))
  27. {
  28. Environment.SetEnvironmentVariable("ORA_SDTZ", oracleSessionTimeZone);
  29. }
  30. // Add services to the container.
  31. builder.Services.AddDbContext<ModelContext>(options =>
  32. options.UseOracle(builder.Configuration["Connection"])
  33. .AddInterceptors(new Kitty_Fall.Apis.Common.OracleTimeZoneInterceptor()));
  34. builder.Services.AddScoped<IUserBusiness, UserBusinessImpl>();
  35. builder.Services.AddScoped<IGameBusiness, GameBusinessImpl>();
  36. // JwtAuthFilter: bảo vệ toàn bộ API bằng JWT (xác thực token, ghi đè msisdn từ token).
  37. builder.Services.AddControllers(options =>
  38. options.Filters.Add<Kitty_Fall.Apis.Filters.JwtAuthFilter>());
  39. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
  40. var app = builder.Build();
  41. // app.UseHttpsRedirection();
  42. app.UseAuthorization();
  43. app.MapControllers();
  44. app.Run();