fix(di): DbContextOptions 수명 Singleton — AddDbContextFactory 스코프 충돌 해소 #3
@@ -49,8 +49,11 @@ builder.Services.Configure<Hc900Options>(builder.Configuration.GetSection("Hc900
|
||||
|
||||
// ── PostgreSQL (hc900 schema) ─────────────────────────────────────────────────
|
||||
Directory.CreateDirectory("data");
|
||||
// optionsLifetime=Singleton: AddDbContextFactory(싱글톤)와 병용 시 DbContextOptions를
|
||||
// 싱글톤으로 공유해야 함(불변 설정이라 동작 무변경; DbContext 자체는 Scoped 유지).
|
||||
builder.Services.AddDbContext<Hc900DbContext>(opt =>
|
||||
opt.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
opt.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")),
|
||||
optionsLifetime: ServiceLifetime.Singleton);
|
||||
builder.Services.AddScoped<IExperionDbService, Hc900DbService>();
|
||||
builder.Services.AddScoped<ITrendService, TrendService>();
|
||||
builder.Services.AddDbContextFactory<Hc900DbContext>();
|
||||
|
||||
Reference in New Issue
Block a user