flutter-rp-example/lib/locator.dart
Nathan SOULIER fff5617757 First commit
2025-03-24 10:12:56 +01:00

61 lines
2.2 KiB
Dart

import 'package:dart_core_sdk/gcs-api.pbgrpc.dart';
import 'package:dart_core_sdk/handlingunitQuery.pbgrpc.dart';
import 'package:dart_core_sdk/proj.pbgrpc.dart';
import 'package:dart_core_sdk/trackingInput.pbgrpc.dart';
import 'package:sampleapp/globals.dart';
import 'package:sampleapp/router/router.dart';
import 'package:sampleapp/services/auth/auth.dart';
import 'package:get_it/get_it.dart';
import 'package:sampleapp/services/gcs.dart';
import 'package:sampleapp/services/grpc_service.dart';
import 'package:sampleapp/utils.dart';
final locator = GetIt.instance;
Future<void> setup() async {
var redirectURI = getRedirectURI();
var callbackUrlScheme = await getCallbackUrlScheme();
AuthService authService = AuthService(
host: Globals.RP_AUTH_BASE_URL,
realm: Globals.RP_AUTH_REALM,
clientId: Globals.RP_AUTH_CLIENT_ID,
redirectUri: redirectURI,
callbackUrlScheme: callbackUrlScheme,
);
locator.registerLazySingleton<AuthService>(() => authService);
locator.registerLazySingleton<ReflexRouterDelegate>(
() => ReflexRouterDelegate(authService));
locator.registerLazySingleton<ProjectServiceClient>(() => GrpcClient.initializeClient(
authService,
Globals.RP_GRPC_HOST,
Globals.RP_GRPC_PORT,
(channel, interceptors) => ProjectServiceClient(channel, interceptors: interceptors),
) as ProjectServiceClient);
locator.registerLazySingleton<GcsApiClient>(() => GrpcClient.initializeClient(
authService,
Globals.RP_GRPC_HOST,
Globals.RP_GRPC_PORT,
(channel, interceptors) => GcsApiClient(channel, interceptors: interceptors),
) as GcsApiClient);
locator.registerLazySingleton<HandlingunitQueryClient>(() => GrpcClient.initializeClient(
authService,
Globals.RP_GRPC_HOST,
Globals.RP_GRPC_PORT,
(channel, interceptors) => HandlingunitQueryClient(channel, interceptors: interceptors),
) as HandlingunitQueryClient);
locator.registerLazySingleton<TrackingInputAPIClient>(() => GrpcClient.initializeClient(
authService,
Globals.RP_GRPC_HOST,
Globals.RP_GRPC_PORT,
(channel, interceptors) => TrackingInputAPIClient(channel, interceptors: interceptors),
) as TrackingInputAPIClient);
locator.registerLazySingleton<GcsService>(() => GcsService());
}