Files
LehrerApp/LehrerApp.Desktop/App.axaml.cs
T
adminandClaude Sonnet 5 db1afff7e4 Fehlerbehandlung, Logging und feldbezogene Validierung (Kapitel 13.2)
Zentrale Exception-Behandlung (Dispatcher.UIThread.UnhandledException,
AppDomain, TaskScheduler) verhindert Abstürze und protokolliert Fehler
über AppLogger in eine rotierende Log-Datei im App-Datenverzeichnis.
Toast-Benachrichtigungen zeigen Erfolg/Fehler global an. Alle Dialoge
mit Formularfeldern zeigen Validierungsmeldungen jetzt direkt am
betroffenen Feld statt in einem Sammel-Label.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-13 12:38:30 +02:00

61 lines
2.4 KiB
C#

using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using LehrerApp.Core.Services;
using LehrerApp.Desktop.Services;
using LehrerApp.Desktop.ViewModels;
using LehrerApp.Desktop.ViewModels.Groups;
using LehrerApp.Desktop.ViewModels.Students;
using LehrerApp.Desktop.Views;
using Microsoft.Extensions.DependencyInjection;
namespace LehrerApp.Desktop;
public class App : Application
{
public static IServiceProvider Services { get; private set; } = null!;
public override void Initialize() => AvaloniaXamlLoader.Load(this);
public override void OnFrameworkInitializationCompleted()
{
Services = AppBootstrapper.BuildServices();
Services.GetRequiredService<AppLogger>().Info("Anwendung gestartet.");
GlobalExceptionHandler.AttachNotifications(Services.GetRequiredService<NotificationService>());
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var mainVm = Services.GetRequiredService<MainWindowViewModel>();
WireCallbacks(mainVm);
desktop.MainWindow = new MainWindow { DataContext = mainVm };
}
base.OnFrameworkInitializationCompleted();
}
private static void WireCallbacks(MainWindowViewModel main)
{
// GroupList → GroupDetail (OnAddGroup wird in GroupListView.axaml.cs verdrahtet)
var gl = Services.GetRequiredService<GroupListViewModel>();
gl.OnNavigateToDetail = (id, tab) => main.NavigateToGroupDetail(id, tab);
// Dashboard → GroupDetail (Chips)
var dash = Services.GetRequiredService<DashboardViewModel>();
dash.OnNavigateToGroup = id => main.NavigateToGroupDetail(id);
// StudentList → StudentDetail + Anlegen
var sl = Services.GetRequiredService<StudentListViewModel>();
sl.OnNavigateToDetail = id => main.NavigateToStudent(id);
sl.OnAddStudent = () => ShowAddStudentDialog();
}
private static async Task ShowAddStudentDialog()
{
var vm = new ViewModels.Students.AddStudentDialogViewModel(
Services.GetRequiredService<Core.Interfaces.IStudentRepository>());
var dialog = new Views.Students.AddStudentDialog { DataContext = vm };
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
await dialog.ShowDialog<bool>(owner);
}
}