From 8059766ba1539613b5c13f4edfbb089c570f79d4 Mon Sep 17 00:00:00 2001 From: Stef Kariotidis Date: Tue, 19 May 2026 08:31:12 +0300 Subject: [PATCH 1/2] WIP: start reset-password CLI scope fix (checkpoint) From 8371b4613edbf539909e44190d3d41618a84f3ad Mon Sep 17 00:00:00 2001 From: Stef Kariotidis Date: Tue, 19 May 2026 08:37:30 +0300 Subject: [PATCH 2/2] fix: scope reset-password CLI services --- Program.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Program.cs b/Program.cs index f0a1ff7a..95889737 100644 --- a/Program.cs +++ b/Program.cs @@ -34,7 +34,7 @@ #region CLI Command Handling // Handling the "reset-password" command from the CLI -if (args.Length > 0 && args[0] == "reset-password") await HandlePasswordResetCommand(args); +if (args.Length > 0 && args[0] == "reset-password") { await HandlePasswordResetCommand(args); return; } #endregion CLI Command Handling @@ -187,7 +187,7 @@ static async Task HandlePasswordResetCommand(string[] args) var username = args[1]; var newPassword = args[2]; - // Rebuild services to handle the password reset + // Build a minimal command host so UserManager is resolved from a normal DI scope. var builder = WebApplication.CreateBuilder(args); builder.Services.AddDbContext(options => options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"), @@ -197,11 +197,10 @@ static async Task HandlePasswordResetCommand(string[] args) .AddEntityFrameworkStores() .AddDefaultTokenProviders(); - var services = builder.Services.BuildServiceProvider(); - - var userManager = services.GetRequiredService>(); + await using var app = builder.Build(); + using var scope = app.Services.CreateScope(); + var userManager = scope.ServiceProvider.GetRequiredService>(); - builder.Services.AddHttpContextAccessor(); var user = await userManager.FindByNameAsync(username); if (user == null) {