60 lines
1.8 KiB
Dart
60 lines
1.8 KiB
Dart
/// Configuration de l'injection de dépendances pour le module Organizations
|
|
library organizations_di;
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import '../data/repositories/organization_repository.dart';
|
|
import '../data/services/organization_service.dart';
|
|
import '../bloc/organizations_bloc.dart';
|
|
|
|
/// Configuration des dépendances du module Organizations
|
|
class OrganizationsDI {
|
|
static final GetIt _getIt = GetIt.instance;
|
|
|
|
/// Enregistre toutes les dépendances du module
|
|
static void registerDependencies() {
|
|
// Repository
|
|
_getIt.registerLazySingleton<OrganizationRepository>(
|
|
() => OrganizationRepositoryImpl(_getIt<Dio>()),
|
|
);
|
|
|
|
// Service
|
|
_getIt.registerLazySingleton<OrganizationService>(
|
|
() => OrganizationService(_getIt<OrganizationRepository>()),
|
|
);
|
|
|
|
// BLoC - Factory pour permettre plusieurs instances
|
|
_getIt.registerFactory<OrganizationsBloc>(
|
|
() => OrganizationsBloc(_getIt<OrganizationService>()),
|
|
);
|
|
}
|
|
|
|
/// Nettoie les dépendances du module
|
|
static void unregisterDependencies() {
|
|
if (_getIt.isRegistered<OrganizationsBloc>()) {
|
|
_getIt.unregister<OrganizationsBloc>();
|
|
}
|
|
if (_getIt.isRegistered<OrganizationService>()) {
|
|
_getIt.unregister<OrganizationService>();
|
|
}
|
|
if (_getIt.isRegistered<OrganizationRepository>()) {
|
|
_getIt.unregister<OrganizationRepository>();
|
|
}
|
|
}
|
|
|
|
/// Obtient une instance du BLoC
|
|
static OrganizationsBloc getOrganizationsBloc() {
|
|
return _getIt<OrganizationsBloc>();
|
|
}
|
|
|
|
/// Obtient une instance du service
|
|
static OrganizationService getOrganizationService() {
|
|
return _getIt<OrganizationService>();
|
|
}
|
|
|
|
/// Obtient une instance du repository
|
|
static OrganizationRepository getOrganizationRepository() {
|
|
return _getIt<OrganizationRepository>();
|
|
}
|
|
}
|