[성현모] DBProvider추가. LoginContext 변경

This commit is contained in:
SHM
2025-07-17 11:54:42 +09:00
parent 7a12be392a
commit 3c5f27ce68
22 changed files with 265 additions and 323 deletions

View File

@ -1,10 +1,14 @@
using AuthApi.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.IdentityModel.Tokens;
using System;
using System.ComponentModel;
using System.Text;
using SystemX.Core.Services;
using WebApi.Library.Config;
using WebApi.Library.DBContext.DB.DBContext.AccountDB.Context;
string configDir = @"../../Config";
string configFileName = "WebApi.AuthApi.Config.json";
@ -26,14 +30,18 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
//singleton
builder.Services.AddSingleton<ConfigService<WebApiConfig>>();
builder.Services.AddScoped<AuthService>();
//scoped
builder.Services.AddScoped<AuthService>();
//db
builder.Services.AddSingleton<DbContextProvider>(); // Generic <20><><EFBFBD><EFBFBD>
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddHttpContextAccessor();
//config preload, auth set
ConfigService<WebApiConfig> preloadConfig = new ConfigService<WebApiConfig>();
@ -61,7 +69,7 @@ if (preloadConfig.OpenConfig($@"{configDir}/{configFileName}") == true)
ValidAudience = $"{config?.Auth?.audience}",
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes($"{config?.Auth?.accessTokenSecret}"))
};
});
});
}
else
{
@ -84,6 +92,24 @@ if (configService?.OpenConfig($@"{configDir}/{configFileName}") == true)
{
serverUrl = $"{apiConfig?.Server?.Address}:{apiConfig?.Server?.Port}";
isIIS = apiConfig!.Server.IIS;
using(var scoped = app.Services.CreateScope())
{
var dbProvider = scoped.ServiceProvider.GetRequiredService<DbContextProvider>();
dbProvider?.SetDBList(apiConfig?.DataBase);
}
//dbcontext set
//app.Use(async (context, next) =>
//{
// var dbProvider = context.RequestServices.GetService<DbContextProvider>();
// // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
// dbProvider?.SetDBList(apiConfig?.DataBase);
// await next.Invoke();
//});
//var dbProviderService = app.Services.GetService<DbContextProvider>();
//dbProviderService?.SetDBList(apiConfig?.DataBase);
}
}
else