File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
src/frontend/src/FinTrack.Maui Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -41,4 +41,32 @@ private async Task InitializeDatabaseAsync()
4141 System . Diagnostics . Debug . WriteLine ( $ "Database initialization failed: { ex . Message } ") ;
4242 }
4343 }
44+
45+ protected override async void OnStart ( )
46+ {
47+ base . OnStart ( ) ;
48+
49+ // Initialize database on app start
50+ await InitializeDatabaseAsync ( ) ;
51+ }
52+
53+ private async Task InitializeDatabaseAsync ( )
54+ {
55+ try
56+ {
57+ // Get the service provider from the current application
58+ var serviceProvider = IPlatformApplication . Current ? . Services ;
59+ if ( serviceProvider != null )
60+ {
61+ using var scope = serviceProvider . CreateScope ( ) ;
62+ var databaseService = scope . ServiceProvider . GetRequiredService < DatabaseService > ( ) ;
63+ await databaseService . InitializeDatabaseAsync ( ) ;
64+ }
65+ }
66+ catch ( Exception ex )
67+ {
68+ // Log error but don't crash the app
69+ System . Diagnostics . Debug . WriteLine ( $ "Database initialization failed: { ex . Message } ") ;
70+ }
71+ }
4472}
Original file line number Diff line number Diff line change @@ -73,6 +73,8 @@ public static MauiApp CreateMauiApp()
7373
7474
7575
76+
77+
7678 return builder . Build ( ) ;
7779 }
7880}
You can’t perform that action at this time.
0 commit comments