[성현모] VPKI 프로젝트 Import

This commit is contained in:
SHM
2025-04-24 15:42:47 +09:00
parent 0a6016bc95
commit 8dcddd431b
188 changed files with 280230 additions and 68 deletions

View File

@ -37,7 +37,6 @@ builder.Services.AddHttpContextAccessor();
builder.Services.AddSingleton<ConfigService<WebApiConfig>>();
//scoped
builder.Services.AddSingleton<EFCoreService>();
builder.Services.AddSingleton<UniqueKeyService>();
//config preload

View File

@ -1,62 +0,0 @@
using DB.HubXDB;
using HubX.Library.Config;
using Microsoft.EntityFrameworkCore;
using SystemX.Core.Config.Model;
using SystemX.Core.DB;
using SystemX.Core.Services;
namespace HubX.Server.Services
{
public class EFCoreService
{
private readonly Dictionary<string, DbContext> DicDbContext = new Dictionary<string, DbContext>();
private readonly ConfigService<WebApiConfig> _configService;
public EFCoreService(ConfigService<WebApiConfig> configService)
{
_configService = configService;
InitializeDB();
}
#region Initialize DBContext
private void InitializeDB()
{
var dbList = _configService.GetConfig()?.DataBase;
if (dbList is not null)
{
foreach (var db in dbList)
{
if (typeof(HubXContext).Name == db.DBContext)
{
CreateDBContext<HubXContext>(db);
}
}
}
}
private void CreateDBContext<TDBContext>(DataBase? dbConfig) where TDBContext : DbContext, new()
{
var connectionString = dbConfig?.ConvertToConnectionString();
var dbContext = new TDBContext();
dbContext.Database.SetConnectionString($"{connectionString}");
if (dbContext is not null)
DicDbContext.Add($"{dbConfig?.DBContext}_{dbConfig?.DBID}", dbContext);
}
#endregion
public TDBContext? GetDBContext<TDBContext>(int dbID = 1) where TDBContext : DbContext
{
TDBContext? dBContext = default;
var dbContextType = typeof(TDBContext);
if (DicDbContext.TryGetValue($"{dbContextType.Name}_{dbID}", out var context) == true)
{
dBContext = context as TDBContext;
}
return dBContext;
}
}//class end
}

View File

@ -11,13 +11,11 @@ using SystemX.Core.DB;
namespace HubX.Server.Services
{
public class UniqueKeyService
{
private readonly EFCoreService _efCoreService;
{
private readonly IServiceScopeFactory _scopeFactory;
public UniqueKeyService(EFCoreService efCoreService, IServiceScopeFactory scopeFactory)
{
_efCoreService = efCoreService;
public UniqueKeyService(IServiceScopeFactory scopeFactory)
{
_scopeFactory = scopeFactory;
}