| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using Database.Database;
- using Kitty_Fall.Apis.Business.Game;
- using Kitty_Fall.Apis.Business.User;
- using log4net;
- using Microsoft.EntityFrameworkCore;
- using Kitty_Fall.Apis.Business;
- using System.Reflection;
- using System.Xml;
- // Use the server OS time zone, ignoring a process-level TZ override.
- // On Linux this uses /etc/localtime; configure the same zone inside a container.
- Environment.SetEnvironmentVariable("TZ", null);
- TimeZoneInfo.ClearCachedData();
- // Oracle session time is configured separately from the process/logging time zone.
- Environment.SetEnvironmentVariable("ORA_SDTZ", "+06:30");
- XmlDocument log4netConfig = new XmlDocument();
- log4netConfig.Load(File.OpenRead("log4net.config"));
- var repo = log4net.LogManager.CreateRepository(
- Assembly.GetEntryAssembly(),
- typeof(log4net.Repository.Hierarchy.Hierarchy)
- );
- log4net.Config.XmlConfigurator.Configure(repo, log4netConfig["log4net"]);
- LogManager.GetLogger(typeof(Program)).Info(
- $"API clock: local={DateTimeOffset.Now:O}, utc={DateTimeOffset.UtcNow:O}, timezone={TimeZoneInfo.Local.Id}");
- var builder = WebApplication.CreateBuilder(args);
- var oracleSessionTimeZone = builder.Configuration["OracleSessionTimeZone"];
- if (!string.IsNullOrWhiteSpace(oracleSessionTimeZone))
- {
- Environment.SetEnvironmentVariable("ORA_SDTZ", oracleSessionTimeZone);
- }
- // Add services to the container.
- builder.Services.AddDbContext<ModelContext>(options =>
- options.UseOracle(builder.Configuration["Connection"])
- .AddInterceptors(new Kitty_Fall.Apis.Common.OracleTimeZoneInterceptor()));
- builder.Services.AddScoped<IUserBusiness, UserBusinessImpl>();
- builder.Services.AddScoped<IGameBusiness, GameBusinessImpl>();
- // JwtAuthFilter: bảo vệ toàn bộ API bằng JWT (xác thực token, ghi đè msisdn từ token).
- builder.Services.AddControllers(options =>
- options.Filters.Add<Kitty_Fall.Apis.Filters.JwtAuthFilter>());
- // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
- var app = builder.Build();
- // app.UseHttpsRedirection();
- app.UseAuthorization();
- app.MapControllers();
- app.Run();
|