@@ -17,62 +17,76 @@ import 'logger_service.dart';
1717final GetIt sl = GetIt .instance;
1818
1919Future <void > injectServices () async {
20- sl.registerLazySingleton <Updater >(() => Updater ());
21-
20+ appLogger.debug ('Initializing storage services...' );
21+ final storage = LocalStorageService ();
22+ final storeUtils = StoreUtils ();
2223 try {
23- appLogger.info ("Initializing LocalStorageService" );
24- final storage = LocalStorageService ();
25- await storage.init ();
26- sl.registerSingleton <LocalStorageService >(storage);
24+ await Future .wait ([storage.init (), storeUtils.init ()]);
25+ appLogger.debug ('Storage services initialized' );
2726
28- appLogger.info ("Initializing StoreUtils" );
29- final storeUtils = StoreUtils ();
30- await storeUtils.init ();
27+ sl.registerSingleton <LocalStorageService >(storage);
3128 sl.registerSingleton <StoreUtils >(storeUtils);
29+ } catch (e, st) {
30+ appLogger.error ('Storage init failed' , e, st);
31+ rethrow ;
32+ }
3233
33- sl.registerLazySingleton (() => AppRouter ());
34- sl.registerLazySingleton (() => AppPurchase ());
35- sl <AppPurchase >().init ();
36- sl.registerLazySingleton <DeepLinkCallbackManager >(
37- () => DeepLinkCallbackManager ());
38- // We want to make sure the platform service and FFI service are
39- // initialized as early as possible so we can communicate with
40- // native code on different platforms.
41- final ps = LanternPlatformService ();
42- await ps.init ();
43- sl.registerSingleton <LanternPlatformService >(ps);
34+ sl.registerLazySingleton <Updater >(() => Updater ());
35+ sl.registerLazySingleton <AppRouter >(() => AppRouter ());
36+ sl.registerLazySingleton <DeepLinkCallbackManager >(
37+ () => DeepLinkCallbackManager (),
38+ );
4439
45- if (PlatformUtils .isFFISupported) {
46- sl.registerLazySingleton (() => LanternFFIService ());
47- await sl <LanternFFIService >().init ();
48- } else {
49- sl.registerLazySingleton <LanternFFIService >(
50- () => MockLanternFFIService ());
51- }
52- sl.registerLazySingleton <LanternService >(
53- () => LanternService (
40+ appLogger.debug ('Initializing AppPurchase...' );
41+ final appPurchase = AppPurchase ();
42+ appPurchase.init ();
43+ sl.registerSingleton <AppPurchase >(appPurchase);
44+ appLogger.debug ('AppPurchase initialized' );
45+
46+ sl.registerSingleton <LanternPlatformService >(LanternPlatformService ());
47+ sl.registerSingleton <LanternFFIService >(
48+ PlatformUtils .isFFISupported
49+ ? LanternFFIService ()
50+ : MockLanternFFIService (),
51+ );
52+
53+ sl.registerSingletonAsync <LanternService >(
54+ () async {
55+ final service = LanternService (
5456 ffiService: sl <LanternFFIService >(),
5557 platformService: sl <LanternPlatformService >(),
5658 appPurchase: sl <AppPurchase >(),
57- ),
58- );
59+ );
60+ try {
61+ await service.init ();
62+ appLogger.debug ('LanternService initialized' );
63+ } catch (e, st) {
64+ appLogger.error ('LanternService init failed' , e, st);
65+ }
66+ return service;
67+ },
68+ );
5969
70+ appLogger.debug ('Initializing notification/Stripe services...' );
71+ final notificationService = NotificationService ();
72+ try {
6073 if (PlatformUtils .isAndroid) {
61- sl.registerSingletonAsync <StripeService >(() async {
62- appLogger.info ("Initializing StripeService" );
63- final stripeService = StripeService ();
64- await stripeService.initialize ();
65- return stripeService;
66- });
67- }
68- sl.registerSingletonAsync <NotificationService >(() async {
69- appLogger.info ("Initializing NotificationService" );
70- final notificationService = NotificationService ();
74+ final stripeService = StripeService ();
75+ await Future .wait ([
76+ notificationService.init (),
77+ stripeService.initialize (),
78+ ]);
79+ sl.registerSingleton <StripeService >(stripeService);
80+ appLogger.debug ('StripeService initialized' );
81+ } else {
7182 await notificationService.init ();
72- return notificationService;
73- });
74- appLogger.info ("All services injected ✅" );
83+ }
7584 } catch (e, st) {
76- appLogger.error ("Error during service injection" , e, st);
85+ appLogger.error ('Notification/Stripe init failed' , e, st);
7786 }
87+ sl.registerSingleton <NotificationService >(notificationService);
88+ appLogger.debug ('NotificationService initialized' );
89+
90+ await sl.allReady ();
91+ appLogger.info ('All services injected ✅' );
7892}
0 commit comments