Created
December 1, 2021 10:01
-
-
Save mondoktamas/6459f81c27d36eff0221227437c23df9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:dio/dio.dart'; | |
import 'package:firebase_messaging/firebase_messaging.dart'; | |
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | |
import 'package:get_it/get_it.dart'; | |
import 'package:skogluft/application/data/chat_service/chat_service.dart'; | |
import 'package:skogluft/application/data/datasource/auth_local_data_store.dart'; | |
import 'package:skogluft/application/data/datasource/auth_service.dart'; | |
import 'package:skogluft/application/data/datasource/token_interceptor.dart'; | |
import 'package:skogluft/application/data/datasource/user_service.dart'; | |
import 'package:skogluft/application/data/notification_service/notification_service.dart'; | |
import 'package:skogluft/application/data/repository/auth_repository_impl.dart'; | |
import 'package:skogluft/application/domain/entity/user.dart'; | |
import 'package:skogluft/application/domain/repository/auth_repository.dart'; | |
import 'package:skogluft/application/features/authorized/features/device_setup/presentation/bloc/device_setup_bloc.dart'; | |
import 'package:skogluft/application/features/authorized/features/home/domain/load_unread_messages_usecase.dart'; | |
import 'package:skogluft/application/features/authorized/features/home/domain/subscribe_unread_messages_usecase.dart'; | |
import 'package:skogluft/application/features/authorized/features/home/presentation/cubit/badge_cubit.dart'; | |
import 'package:skogluft/application/features/authorized/features/home/presentation/cubit/main_page_cubit.dart'; | |
import 'package:skogluft/application/features/authorized/features/light_schedule/features/create/cubit/create_slot_cubit.dart'; | |
import 'package:skogluft/application/features/authorized/features/light_schedule/features/update/cubit/update_slot_cubit.dart'; | |
import 'package:skogluft/application/features/authorized/features/light_schedule/presentation/cubit/light_schedule_cubit.dart'; | |
import 'package:skogluft/application/features/authorized/features/my_account/domain/logout_usecase.dart'; | |
import 'package:skogluft/application/features/authorized/features/my_account/presentation/bloc/my_account_bloc.dart'; | |
import 'package:skogluft/application/features/authorized/features/plant_support/domain/connect_support_usecase.dart'; | |
import 'package:skogluft/application/features/authorized/features/plant_support/domain/disconnect_support_usecase.dart'; | |
import 'package:skogluft/application/features/authorized/features/plant_support/domain/mark_messages_as_read_usecase.dart'; | |
import 'package:skogluft/application/features/authorized/features/plant_support/domain/send_image_usecase.dart'; | |
import 'package:skogluft/application/features/authorized/features/plant_support/domain/send_message_usecase.dart'; | |
import 'package:skogluft/application/features/authorized/features/plant_support/domain/subscribe_to_message_usecase.dart'; | |
import 'package:skogluft/application/features/authorized/features/plant_support/presentation/cubit/plant_support_cubit.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/confirm_forgot_password/domain/confirm_forgot_password_email_usecase.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/confirm_forgot_password/domain/confirm_forgot_password_usecase.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/confirm_forgot_password/presentation/bloc/confirm_forgot_password_bloc.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/confirm_forgot_password/presentation/forgot_password_deeplink_handler.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/instructions/data/datasource/instructions_local_data_source.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/instructions/data/datasource/instructions_mock_service.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/instructions/data/datasource/instructions_service.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/instructions/data/repository/instructions_repository.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/instructions/domain/repository/instructions_repository.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/instructions/domain/usecase/fetch_instructions_usecase.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/instructions/presentation/bloc/instructions_bloc.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/reset_password/domain/usecase/reset_password_usecase.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/reset_password/presentation/bloc/reset_password_bloc.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/signin/domain/usecase/sign_in_usecase.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/signin/domain/usecase/social_sign_in_usecase.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/signin/presentation/bloc/sign_in_bloc.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/signup/domain/usecase/sign_up_usecase.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/signup/presentation/bloc/sign_up_bloc.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/signup_confirmation/domain/confirm_signup_usecase.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/signup_confirmation/presentation/bloc/sign_up_confirmation_bloc.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/signup_confirmation/presentation/sign_up_confirmation_deeplink_handler.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/start/presentation/bloc/start_page_bloc.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/verify_email/domain/resend_verification_email_usecase.dart'; | |
import 'package:skogluft/application/features/unauthorized/features/verify_email/presentation/bloc/verify_email_bloc.dart'; | |
import 'package:skogluft/application/presentation/bloc/auth_bloc.dart'; | |
import 'package:skogluft/application/presentation/deeplink/dynamic_links_handler.dart'; | |
import 'package:skogluft/application/presentation/router/router.gr.dart'; | |
import 'package:skogluft/core/deeplink/deeplink_handler.dart'; | |
import 'package:zendesk2/zendesk2.dart'; | |
final getIt = GetIt.instance; | |
const baseScope = 'baseScope'; | |
const unauthorizedScope = 'unauthorizedScope'; | |
const authorizedScope = 'authorizedScope'; | |
void setupAppScope() { | |
getIt.registerLazySingleton<Dio>(() => Dio()..interceptors.add(TokenInterceptor())); | |
getIt.registerLazySingleton<FlutterSecureStorage>(() => const FlutterSecureStorage()); | |
getIt.registerLazySingleton<AppRouter>(() => AppRouter()); | |
getIt.registerLazySingleton<AuthLocalDataStore>( | |
() => AuthLocalDataStoreImpl(getIt<FlutterSecureStorage>()), | |
); | |
getIt.registerLazySingleton<InstructionsLocalDataSource>( | |
() => InstructionsLocalDataSourceImpl(getIt<FlutterSecureStorage>()), | |
); | |
getIt.registerLazySingleton<AuthService>(() => AuthService(getIt<Dio>())); | |
// getIt.registerLazySingleton<InstructionsService>(() => InstructionsService(getIt<Dio>())); | |
//TODO remove the below line and uncomment the above line when api call will be available!!! | |
getIt.registerLazySingleton<InstructionsService>(() => MockInstructionsService()); | |
getIt.registerLazySingleton<UserService>(() => UserService(getIt<Dio>())); | |
getIt.registerLazySingleton<AuthRepository>( | |
() => AuthRepositoryImpl( | |
getIt<AuthService>(), | |
getIt<UserService>(), | |
getIt<AuthLocalDataStore>(), | |
), | |
); | |
getIt.registerLazySingleton<InstructionsRepository>( | |
() => InstructionsRepositoryImpl( | |
getIt<InstructionsService>(), | |
getIt<InstructionsLocalDataSource>(), | |
), | |
); | |
getIt.registerFactory<Stream<User?>>( | |
() => getIt<AuthRepository>().currentUserStream.asBroadcastStream(), | |
); | |
getIt.registerLazySingleton<AuthBloc>( | |
() => AuthBloc(getIt<AuthRepository>(), getIt<Stream<User?>>()), | |
); | |
getIt.registerLazySingleton<MultiDeepLinkHandler>(() => MultiDeepLinkHandler(handlers: [])); | |
getIt.registerLazySingleton<DynamicLinksHandler>( | |
() => DynamicLinksHandler(getIt<MultiDeepLinkHandler>()), | |
); | |
} | |
Future<void> setupUnauthorizedScope() async { | |
if (getIt.currentScopeName == unauthorizedScope) return; | |
if (getIt.currentScopeName == authorizedScope) { | |
await getIt.popScope(); | |
} | |
getIt.pushNewScope( | |
scopeName: unauthorizedScope, | |
init: (getIt) { | |
getIt.registerLazySingleton<DeepLinkHandler>( | |
() => ForgotPasswordDeeplinkHandler(getIt<AppRouter>()), | |
instanceName: 'change_password_deeplink_handler', | |
); | |
getIt.registerLazySingleton<DeepLinkHandler>( | |
() => SignUpConfirmationDeeplinkHandler(getIt<AppRouter>(), getIt<SignUpBloc>()), | |
instanceName: 'sign_up_confirmation_deeplink_handler', | |
); | |
getIt.registerLazySingleton<SignInUseCase>(() => SignInUseCase(getIt<AuthRepository>())); | |
getIt.registerLazySingleton<SocialSignInUseCase>( | |
() => SocialSignInUseCase(getIt<AuthRepository>()), | |
); | |
getIt.registerLazySingleton<StartPageBloc>(() => StartPageBloc(getIt<SocialSignInUseCase>())); | |
getIt.registerLazySingleton<SignInBloc>( | |
() => SignInBloc(getIt<SignInUseCase>(), getIt<SocialSignInUseCase>()), | |
); | |
getIt.registerLazySingleton<SignUpUseCase>(() => SignUpUseCase(getIt<AuthRepository>())); | |
getIt.registerLazySingleton<SignUpBloc>( | |
() => SignUpBloc(getIt<SignUpUseCase>(), getIt<SocialSignInUseCase>()), | |
); | |
getIt.registerLazySingleton<ConfirmSignUpUseCase>( | |
() => ConfirmSignUpUseCase( | |
getIt<AuthRepository>(), | |
getIt<AuthLocalDataStore>(), | |
), | |
); | |
getIt.registerFactory<SignUpConfirmationBloc>( | |
() => SignUpConfirmationBloc( | |
getIt<ConfirmSignUpUseCase>(), | |
getIt<ResendVerificationEmailUseCase>(), | |
getIt<SignInUseCase>(), | |
), | |
); | |
getIt.registerLazySingleton<ResetPasswordUseCase>( | |
() => ResetPasswordUseCase(getIt<AuthRepository>()), | |
); | |
getIt.registerFactory<ResetPasswordBloc>( | |
() => ResetPasswordBloc(getIt<ResetPasswordUseCase>()), | |
); | |
getIt.registerLazySingleton<ConfirmForgotPasswordUseCase>( | |
() => ConfirmForgotPasswordUseCase(getIt<AuthRepository>()), | |
); | |
getIt.registerLazySingleton<StoredEmailUseCase>( | |
() => StoredEmailUseCase(getIt<AuthLocalDataStore>())); | |
getIt.registerFactory<ConfirmForgotPasswordBloc>( | |
() => ConfirmForgotPasswordBloc( | |
getIt<ConfirmForgotPasswordUseCase>(), | |
getIt<SignInUseCase>(), | |
getIt<StoredEmailUseCase>(), | |
), | |
); | |
getIt.registerLazySingleton<ResendVerificationEmailUseCase>( | |
() => ResendVerificationEmailUseCase( | |
getIt<AuthRepository>(), | |
getIt<AuthLocalDataStore>(), | |
), | |
); | |
getIt.registerFactory<VerifyEmailBloc>( | |
() => VerifyEmailBloc(getIt<ResendVerificationEmailUseCase>()), | |
); | |
getIt.registerLazySingleton<FetchInstructionsUseCase>( | |
() => FetchInstructionsUseCase(getIt<InstructionsRepository>()), | |
); | |
getIt.registerLazySingleton<InstructionsBloc>( | |
() => InstructionsBloc(getIt<FetchInstructionsUseCase>()), | |
); | |
final multiDeeplinkHandler = getIt<MultiDeepLinkHandler>(); | |
final changePasswordDeeplinkHandler = | |
getIt<DeepLinkHandler>(instanceName: 'change_password_deeplink_handler'); | |
final signUpConfirmationDeeplinkHandler = | |
getIt<DeepLinkHandler>(instanceName: 'sign_up_confirmation_deeplink_handler'); | |
multiDeeplinkHandler.addHandler(changePasswordDeeplinkHandler); | |
multiDeeplinkHandler.addHandler(signUpConfirmationDeeplinkHandler); | |
}, | |
dispose: () { | |
final multiDeeplinkHandler = getIt<MultiDeepLinkHandler>(); | |
final changePasswordDeeplinkHandler = | |
getIt<DeepLinkHandler>(instanceName: 'change_password_deeplink_handler'); | |
final signUpConfirmationDeeplinkHandler = | |
getIt<DeepLinkHandler>(instanceName: 'sign_up_confirmation_deeplink_handler'); | |
multiDeeplinkHandler.removeHandler(changePasswordDeeplinkHandler); | |
multiDeeplinkHandler.removeHandler(signUpConfirmationDeeplinkHandler); | |
}, | |
); | |
} | |
Future<void> setupAuthorizedScope() async { | |
if (getIt.currentScopeName == authorizedScope) return; | |
if (getIt.currentScopeName == unauthorizedScope) { | |
await getIt.popScope(); | |
} | |
getIt.pushNewScope( | |
scopeName: authorizedScope, | |
init: (getIt) { | |
getIt.registerLazySingleton<NotificationService>(() => NotificationServiceImpl( | |
getIt<FlutterSecureStorage>(), FirebaseMessaging.instance, Zendesk2Chat.instance)); | |
getIt.registerLazySingleton<SubscribeUnreadMessagesUseCase>( | |
() => SubscribeUnreadMessagesUseCase(getIt<NotificationService>())); | |
getIt.registerLazySingleton<LoadUnreadMessagesUseCase>( | |
() => LoadUnreadMessagesUseCase(getIt<NotificationService>())); | |
getIt.registerLazySingleton<BadgeCubit>(() => BadgeCubit( | |
getIt<SubscribeUnreadMessagesUseCase>(), | |
getIt<LoadUnreadMessagesUseCase>(), | |
)); | |
getIt.registerLazySingleton<MainPageBloc>(() => MainPageBloc()); | |
getIt.registerLazySingleton<LogoutUseCase>(() => LogoutUseCase(getIt<AuthRepository>())); | |
getIt.registerSingletonAsync<MyAccountBloc>(() async { | |
final user = await getIt<Stream<User?>>().where((user) => user != null).cast<User>().first; | |
return MyAccountBloc(user, getIt<LogoutUseCase>()); | |
}); | |
getIt.registerLazySingleton<ResetPasswordUseCase>( | |
() => ResetPasswordUseCase(getIt<AuthRepository>()), | |
); | |
getIt.registerFactory<ResetPasswordBloc>( | |
() => ResetPasswordBloc(getIt<ResetPasswordUseCase>()), | |
); | |
getIt.registerLazySingleton<FetchInstructionsUseCase>( | |
() => FetchInstructionsUseCase(getIt<InstructionsRepository>()), | |
); | |
getIt.registerLazySingleton<InstructionsBloc>( | |
() => InstructionsBloc(getIt<FetchInstructionsUseCase>()), | |
); | |
getIt.registerFactory<DeviceSetupBloc>(() => DeviceSetupBloc()); | |
getIt.registerFactory<LightScheduleCubit>(() => LightScheduleCubit()); | |
getIt.registerFactory<CreateSlotCubit>(() => CreateSlotCubit()); | |
getIt.registerFactory<UpdateSlotCubit>(() => UpdateSlotCubit()); | |
getIt.registerSingletonAsync<ChatService>(() async { | |
final user = await getIt<Stream<User?>>().where((user) => user != null).cast<User>().first; | |
return ChatServiceImpl(Zendesk.instance, Zendesk2Chat.instance, user); | |
}); | |
getIt.registerLazySingleton<SendMessageUseCase>( | |
() => SendMessageUseCase(getIt<ChatService>())); | |
getIt.registerLazySingleton<SubscribeToMessagesUseCase>( | |
() => SubscribeToMessagesUseCase(getIt<ChatService>())); | |
getIt.registerLazySingleton<SendImageUseCase>(() => SendImageUseCase(getIt<ChatService>())); | |
getIt.registerLazySingleton<ConnectSupportUseCase>( | |
() => ConnectSupportUseCase(getIt<ChatService>())); | |
getIt.registerLazySingleton<DisconnectSupportUseCase>( | |
() => DisconnectSupportUseCase(getIt<ChatService>())); | |
getIt.registerLazySingleton<MarkMessagesAsReadUseCase>( | |
() => MarkMessagesAsReadUseCase(getIt<NotificationService>())); | |
getIt.registerLazySingleton<PlantSupportCubit>( | |
() => PlantSupportCubit( | |
getIt<SendMessageUseCase>(), | |
getIt<SubscribeToMessagesUseCase>(), | |
getIt<SendImageUseCase>(), | |
getIt<ConnectSupportUseCase>(), | |
getIt<DisconnectSupportUseCase>(), | |
getIt<MarkMessagesAsReadUseCase>(), | |
), | |
); | |
}, | |
dispose: () async { | |
await getIt<ChatService>().dispose(); | |
await getIt<NotificationService>().dispose(); | |
}, | |
); | |
return getIt.allReady(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment