configureFirePushNotificationInjection function

Future<void> configureFirePushNotificationInjection(
  1. AppEnvironment environment,
  2. FirePushNotificationsConfig config, {
  3. Logger? logger,
})

Implementation

Future<void> configureFirePushNotificationInjection(
  AppEnvironment environment,
  FirePushNotificationsConfig config, {
  Logger? logger,
}) async {
  if (!getItPushNotifications.isRegistered<SharedPreferences>()) {
    if (AppEnvironment.test != environment) {
      getItPushNotifications.registerSingletonAsync<SharedPreferences>(() => SharedPreferences.getInstance());
    }
  }

  if (!getItPushNotifications.isRegistered<FirePushNotificationsConfig>()) {
    getItPushNotifications.registerSingleton<FirePushNotificationsConfig>(config);
  }

  if (!getItPushNotifications.isRegistered<DeviceInfoFacade>()) {
    getItPushNotifications.registerSingletonAsync<DeviceInfoFacade>(() async {
      return DeviceInfoFacadeImpl(
        config: config,
        sharedPreferences: getItPushNotifications(),
      );
    });
  }

  if (!getItPushNotifications.isRegistered<FirebaseNotificationFacade>()) {
    getItPushNotifications.registerSingletonAsync<FirebaseNotificationFacade>(() async {
      return FirebaseNotificationFacadeImpl(
        firebaseMessaging: FirebaseMessaging.instance,
        config: config,
      );
    });
  }

  getItPushNotifications.registerSingletonAsync<PushNotificationsService>(
    () async {
      return PushNotificationsServiceImpl(
        client: getItPushNotifications(),
        firebaseFacade: getItPushNotifications(),
        globalConfig: config,
        logger: logger,
      );
    },
    dependsOn: [
      if (AppEnvironment.test != environment) IHttpClient,
    ],
  );

  await getItPushNotifications.isReady<PushNotificationsService>();
}