fix(di): DbContextOptions 수명 Singleton — AddDbContextFactory 병용 스코프 충돌 해소
AddDbContextFactory(싱글톤)가 Scoped DbContextOptions를 소비해 Development의 ValidateOnBuild에서 기동 크래시. optionsLifetime=Singleton으로 옵션을 공유 (불변 설정이라 동작 무변경; DbContext 자체는 Scoped 유지). EF Core 권장 패턴. Development 재기동으로 검증. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -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