60 lines
1.8 KiB
Dart
60 lines
1.8 KiB
Dart
/// Configuration de l'injection de dépendances pour le module Organisations
|
|
library organisations_di;
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import '../data/repositories/organisation_repository.dart';
|
|
import '../data/services/organisation_service.dart';
|
|
import '../bloc/organisations_bloc.dart';
|
|
|
|
/// Configuration des dépendances du module Organisations
|
|
class OrganisationsDI {
|
|
static final GetIt _getIt = GetIt.instance;
|
|
|
|
/// Enregistre toutes les dépendances du module
|
|
static void registerDependencies() {
|
|
// Repository
|
|
_getIt.registerLazySingleton<OrganisationRepository>(
|
|
() => OrganisationRepositoryImpl(_getIt<Dio>()),
|
|
);
|
|
|
|
// Service
|
|
_getIt.registerLazySingleton<OrganisationService>(
|
|
() => OrganisationService(_getIt<OrganisationRepository>()),
|
|
);
|
|
|
|
// BLoC - Factory pour permettre plusieurs instances
|
|
_getIt.registerFactory<OrganisationsBloc>(
|
|
() => OrganisationsBloc(_getIt<OrganisationService>()),
|
|
);
|
|
}
|
|
|
|
/// Nettoie les dépendances du module
|
|
static void unregisterDependencies() {
|
|
if (_getIt.isRegistered<OrganisationsBloc>()) {
|
|
_getIt.unregister<OrganisationsBloc>();
|
|
}
|
|
if (_getIt.isRegistered<OrganisationService>()) {
|
|
_getIt.unregister<OrganisationService>();
|
|
}
|
|
if (_getIt.isRegistered<OrganisationRepository>()) {
|
|
_getIt.unregister<OrganisationRepository>();
|
|
}
|
|
}
|
|
|
|
/// Obtient une instance du BLoC
|
|
static OrganisationsBloc getOrganisationsBloc() {
|
|
return _getIt<OrganisationsBloc>();
|
|
}
|
|
|
|
/// Obtient une instance du service
|
|
static OrganisationService getOrganisationService() {
|
|
return _getIt<OrganisationService>();
|
|
}
|
|
|
|
/// Obtient une instance du repository
|
|
static OrganisationRepository getOrganisationRepository() {
|
|
return _getIt<OrganisationRepository>();
|
|
}
|
|
}
|