configureAuthenticationAdvancedInjection function
Future<void>
configureAuthenticationAdvancedInjection(
- AppEnvironment environment,
- AuthenticationFireSocialConfig config, {
- AuthenticationSocialService customAuthServiceFactory()?,
This functions register:
SharedPreferences if not registered previously
IHttpClient if not registered previously
AuthenticationFireSocialConfig if not registered previously
GoogleSignInFacade if not registered previously
FacebookSignInFacade if not registered previously
AppleSignInFacade if not registered previously
AuthenticationService with AuthenticationServiceImpl implementation, if passed test environment, it will provide
a AuthenticationServiceMock
It also provides a way to implement custom implementation of AuthenticationService
Implementation
Future<void> configureAuthenticationAdvancedInjection(
AppEnvironment environment,
AuthenticationFireSocialConfig config, {
AuthenticationSocialService Function()? customAuthServiceFactory,
}) async {
final getIt = GetIt.instance;
if (!getIt.isRegistered<SharedPreferences>()) {
if (AppEnvironment.test != environment) {
getIt.registerSingletonAsync<SharedPreferences>(() => SharedPreferences.getInstance());
}
}
if (!getIt.isRegistered<GoogleSignInFacade>()) {
if (AppEnvironment.test != environment) {
getIt.registerSingletonAsync<GoogleSignInFacade>(
() async => UnimplementedGoogleSignInFacade(),
);
}
}
if (!getIt.isRegistered<FacebookSignInFacade>()) {
if (AppEnvironment.test != environment) {
getIt.registerSingletonAsync<FacebookSignInFacade>(() async => UnimplementedFacebookSignInFacade());
}
}
if (!getIt.isRegistered<AppleSignInFacade>()) {
if (AppEnvironment.test != environment) {
getIt.registerSingletonAsync<AppleSignInFacade>(
() async => UnimplementedAppleSignInFacade(),
);
}
}
if (!getIt.isRegistered<AnonymousFacade>()) {
if (AppEnvironment.test != environment) {
getIt.registerSingletonAsync<AnonymousFacade>(
() async => AnonymousFacadeImpl(),
);
}
}
// if (!getIt.isRegistered<IHttpClient>()) {
// if (AppEnvironment.test != environment) {
// getIt.registerSingletonAsync<IHttpClient>(
// () async => HttpClientImpl(
// sharedPreferences: getIt(),
// maxAge: config.maxAge,
// // refreshTokenDebounceTime: config.refreshTokenDebounceTime,
// refreshTokenMethod: config.refreshTokenMethod,
// refreshTokenUrl: config.refreshTokenAPIendpoint,
// customRefreshTokenRequestBodyMapper: config.customRefreshTokenRequestBodyMapper,
// customRefreshTokenResponseParser: config.customRefreshTokenResponseParser,
// onRefreshToken: config.onRefreshToken,
// refreshTokenTimeout: config.refreshTokenTimeout,
// ),
// dependsOn: [
// SharedPreferences,
// ],
// );
// }
// }
configureAuthenticationBasicInjection(
environment,
config,
customService: (client) {
if (customAuthServiceFactory != null) {
return customAuthServiceFactory();
}
return AuthenticationSocialServiceImpl(
config: config,
httpClient: getIt(),
sharedPreferences: getIt(),
appleSignInFacade: getIt(),
facebookSignInFacade: getIt(),
googleSignInFacade: getIt(),
anonymouslySignInFacade: getIt(),
logger: getAuthenticationSocialLogger(config),
);
},
);
if (!getIt.isRegistered<AuthenticationFireSocialConfig>()) {
getIt.registerSingleton<AuthenticationFireSocialConfig>(config);
}
// if (!getIt.isRegistered<AuthenticationService>()) {
// getIt.registerSingletonAsync<AuthenticationService>(
// () async {
// if (AppEnvironment.test == environment) {
// return MockAuthenticationSocialService();
// }
// if (customAuthServiceFactory != null) {
// return customAuthServiceFactory();
// }
// return AuthenticationSocialServiceImpl(
// config: config,
// httpClient: getIt(),
// sharedPreferences: getIt(),
// appleSignInFacade: getIt(),
// facebookSignInFacade: getIt(),
// googleSignInFacade: getIt(),
// logger: getAuthenticationSocialLogger(config),
// );
// },
// dependsOn: [
// if (AppEnvironment.test != environment) IHttpClient,
// if (AppEnvironment.test != environment) SharedPreferences,
// if (AppEnvironment.test != environment) AppleSignInFacade,
// if (AppEnvironment.test != environment) FacebookSignInFacade,
// if (AppEnvironment.test != environment) GoogleSignInFacade,
// ],
// );
// }
await getIt.isReady<AuthenticationService>();
getIt.registerSingleton<AuthenticationSocialService>(
getIt<AuthenticationService>() as AuthenticationSocialService,
);
}