BuildServiceProviderWithSelf无用,改用原生方法

This commit is contained in:
Falcon 2026-10-21 15:42:31 +08:00
parent 495e52c2e6
commit bfcfa4ee9b

View File

@ -21,9 +21,9 @@ namespace PrivateBox
services.AddSingleton(appConfig); services.AddSingleton(appConfig);
services.AddSingleton<AppRunTimeSettings>(); services.AddSingleton<AppRunTimeSettings>();
AddServices(services,appConfig); AddServices(services,appConfig);
using var providerScope = services.BuildServiceProviderWithSelf().CreateScope(); using var providerScope = services.BuildServiceProvider().CreateScope();
var sp = providerScope.ServiceProvider; var sp = providerScope.ServiceProvider;
var logger = sp.GetRequiredService<ILoggerFactory>().CreateLogger("PrivateBoxMain"); var logger = sp.GetRequiredService<ILoggerFactory>().CreateLogger("Main");
var mainForm = sp.GetRequiredService<MainForm>(); var mainForm = sp.GetRequiredService<MainForm>();
logger.LogInformation($"Application will run main:{mainForm.GetType().FullName}"); logger.LogInformation($"Application will run main:{mainForm.GetType().FullName}");
Application.Run(mainForm); Application.Run(mainForm);