From 12d90c1d79a9664869bf2ca17edffddfe7a6c599 Mon Sep 17 00:00:00 2001 From: windpacer Date: Thu, 18 Jun 2026 10:06:29 +0900 Subject: [PATCH] =?UTF-8?q?fix(di):=20DbContextOptions=20=EC=88=98?= =?UTF-8?q?=EB=AA=85=20Singleton=20=E2=80=94=20AddDbContextFactory=20?= =?UTF-8?q?=EB=B3=91=EC=9A=A9=20=EC=8A=A4=EC=BD=94=ED=94=84=20=EC=B6=A9?= =?UTF-8?q?=EB=8F=8C=20=ED=95=B4=EC=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AddDbContextFactory(싱글톤)가 Scoped DbContextOptions를 소비해 Development의 ValidateOnBuild에서 기동 크래시. optionsLifetime=Singleton으로 옵션을 공유 (불변 설정이라 동작 무변경; DbContext 자체는 Scoped 유지). EF Core 권장 패턴. Development 재기동으로 검증. Co-Authored-By: Claude Opus 4.8 --- src/Hc900Crawler/Program.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Hc900Crawler/Program.cs b/src/Hc900Crawler/Program.cs index 6bc5e28..8631a3e 100644 --- a/src/Hc900Crawler/Program.cs +++ b/src/Hc900Crawler/Program.cs @@ -49,8 +49,11 @@ builder.Services.Configure(builder.Configuration.GetSection("Hc900 // ── PostgreSQL (hc900 schema) ───────────────────────────────────────────────── Directory.CreateDirectory("data"); +// optionsLifetime=Singleton: AddDbContextFactory(싱글톤)와 병용 시 DbContextOptions를 +// 싱글톤으로 공유해야 함(불변 설정이라 동작 무변경; DbContext 자체는 Scoped 유지). builder.Services.AddDbContext(opt => - opt.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); + opt.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")), + optionsLifetime: ServiceLifetime.Singleton); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddDbContextFactory();