1- using System . Windows ;
1+ using CommunityToolkit . Mvvm . Messaging ;
2+ using FinTrack . Core ;
3+ using FinTrack . Services ;
4+ using FinTrack . Services . Api ;
5+ using FinTrack . ViewModels ;
6+ using FinTrack . Views ;
7+ using Microsoft . Extensions . DependencyInjection ;
8+ using Microsoft . Extensions . Hosting ;
9+ using Microsoft . Extensions . Logging ;
10+ using Serilog ;
11+ using System . Windows ;
212
313namespace FinTrack
414{
515 public partial class App : Application
616 {
7- protected override void OnStartup ( StartupEventArgs e )
17+ private readonly IHost _host ;
18+
19+ public App ( )
20+ {
21+ _host = Host . CreateDefaultBuilder ( )
22+ . UseSerilog ( ( context , services , configuration ) =>
23+ {
24+ configuration . ReadFrom . Configuration ( context . Configuration ) ;
25+ } )
26+ . ConfigureServices ( ( context , services ) =>
27+ {
28+ ConfigureServices ( services ) ;
29+ } )
30+ . Build ( ) ;
31+
32+ SetupGlobalExceptionHandling ( ) ;
33+ }
34+
35+ private void ConfigureServices ( IServiceCollection services )
36+ {
37+ services . AddSingleton < IMessenger > ( WeakReferenceMessenger . Default ) ;
38+
39+ services . AddSingleton < MainWindow > ( ) ;
40+ services . AddSingleton < AuthenticatorWindow > ( ) ;
41+
42+ services . AddSingleton < MainViewModel > ( ) ;
43+ services . AddSingleton < LoginViewModel > ( ) ;
44+
45+ services . AddTransient < TopBarViewModel > ( ) ;
46+ services . AddTransient < BottomBarViewModel > ( ) ;
47+
48+ services . AddTransient < RegisterViewModel > ( ) ;
49+ services . AddTransient < OtpVerificationViewModel > ( ) ;
50+ services . AddTransient < ForgotPasswordViewModel > ( ) ;
51+ services . AddTransient < ApplicationRecognizeSlideViewModel > ( ) ;
52+ services . AddTransient < AuthenticatorViewModel > ( ) ;
53+ services . AddTransient < DashboardViewModel > ( ) ;
54+ services . AddTransient < BudgetViewModel > ( ) ;
55+ services . AddTransient < AccountViewModel > ( ) ;
56+ services . AddTransient < TransactionsViewModel > ( ) ;
57+ services . AddTransient < ReportsViewModel > ( ) ;
58+ services . AddTransient < FinBotViewModel > ( ) ;
59+ services . AddTransient < CurrenciesViewModel > ( ) ;
60+ services . AddTransient < DebtViewModel > ( ) ;
61+ services . AddTransient < SettingsViewModel > ( ) ;
62+ services . AddTransient < FeedbackViewModel > ( ) ;
63+ services . AddTransient < NotificationViewModel > ( ) ;
64+
65+ services . AddSingleton < IAuthService , AuthService > ( ) ;
66+ services . AddSingleton < ISecureTokenStorage , SecureTokenStorage > ( ) ;
67+ services . AddSingleton < IApiService , ApiService > ( ) ;
68+ }
69+
70+ protected override async void OnStartup ( StartupEventArgs e )
871 {
72+ await _host . StartAsync ( ) ;
73+
74+ var logger = _host . Services . GetRequiredService < ILogger < App > > ( ) ;
75+ logger . LogInformation ( "Uygulama başlatıldı ve Host çalışıyor." ) ;
76+
77+ var window = _host . Services . GetRequiredService < AuthenticatorWindow > ( ) ;
78+ window . Show ( ) ;
79+
980 base . OnStartup ( e ) ;
10- new LoginWindow ( ) . Show ( ) ;
81+ }
82+
83+ private void SetupGlobalExceptionHandling ( )
84+ {
85+ DispatcherUnhandledException += ( sender , e ) =>
86+ {
87+ var logger = _host . Services . GetRequiredService < ILogger < App > > ( ) ;
88+ logger . LogCritical ( e . Exception , "YAKALANAMAYAN UI HATASI!" ) ;
89+
90+ MessageBox . Show ( "Beklenmedik bir hata oluştu. Uygulama kapanacak. Detaylar log dosyasına yazıldı." , "Kritik Hata" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
91+ e . Handled = true ;
92+ Shutdown ( ) ;
93+ } ;
94+
95+ AppDomain . CurrentDomain . UnhandledException += ( sender , e ) =>
96+ {
97+ var logger = _host . Services . GetRequiredService < ILogger < App > > ( ) ;
98+ logger . LogCritical ( e . ExceptionObject as Exception , "YAKALANAMAYAN ARKA PLAN HATASI!" ) ;
99+ } ;
100+ }
101+
102+ protected override async void OnExit ( ExitEventArgs e )
103+ {
104+ using ( _host )
105+ {
106+ await _host . StopAsync ( TimeSpan . FromSeconds ( 5 ) ) ;
107+ }
108+ base . OnExit ( e ) ;
11109 }
12110 }
13111}
0 commit comments