Review der Codebase

This commit is contained in:
2026-08-13 19:57:48 +02:00
parent d987b93315
commit 27359794f7
9 changed files with 269 additions and 80 deletions
+34 -5
View File
@@ -15,6 +15,8 @@ namespace LehrerApp.Desktop;
public class App : Application
{
public static IServiceProvider Services { get; private set; } = null!;
private static ServiceProvider? _serviceProvider;
private static bool _exitHandlerAttached;
public override void Initialize() => AvaloniaXamlLoader.Load(this);
@@ -32,31 +34,58 @@ public class App : Application
promptVm.OnUnlocked = password =>
{
AppBootstrapper.DbPassword = password;
StartMainApp(desktop);
StartMainApp(desktop, showImmediately: true);
promptWindow.Close();
};
desktop.MainWindow = promptWindow;
}
else
{
StartMainApp(desktop);
StartMainApp(desktop, showImmediately: false);
}
}
base.OnFrameworkInitializationCompleted();
}
private static void StartMainApp(IClassicDesktopStyleApplicationLifetime desktop)
private static void StartMainApp(
IClassicDesktopStyleApplicationLifetime desktop, bool showImmediately)
{
Services = AppBootstrapper.BuildServices();
_serviceProvider = AppBootstrapper.BuildServices();
Services = _serviceProvider;
Services.GetRequiredService<AppLogger>().Info("Anwendung gestartet.");
GlobalExceptionHandler.AttachNotifications(Services.GetRequiredService<NotificationService>());
if (!_exitHandlerAttached)
{
desktop.Exit += (_, _) => DisposeServices();
_exitHandlerAttached = true;
}
var mainVm = Services.GetRequiredService<MainWindowViewModel>();
WireCallbacks(mainVm);
var main = new MainWindow { DataContext = mainVm };
desktop.MainWindow = main;
main.Show();
if (showImmediately) main.Show();
}
private static void DisposeServices()
{
if (_serviceProvider is null) return;
try
{
_serviceProvider.GetService<LiteDbContext>()?.Checkpoint();
}
catch (Exception ex)
{
AppBootstrapper.Logger.Error("Datenbank-Checkpoint beim Beenden fehlgeschlagen.", ex);
}
finally
{
_serviceProvider.Dispose();
_serviceProvider = null;
}
}
private static void WireCallbacks(MainWindowViewModel main)