102 lines
3.1 KiB
Dart
102 lines
3.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import 'package:internet_connection_checker/internet_connection_checker.dart';
|
|
import 'package:mc_gallery/features/core/abstracts/router/app_router.dart';
|
|
import 'package:mc_gallery/features/core/services/logging_service.dart';
|
|
import 'package:mc_gallery/features/core/services/navigation_service.dart';
|
|
import 'package:mc_gallery/features/home/api/unsplash_images_api.dart';
|
|
import 'package:mc_gallery/features/home/services/image_cache_manager_service.dart';
|
|
import 'package:mc_gallery/features/home/services/images_service.dart';
|
|
import 'package:mc_gallery/features/home/views/gallery/gallery_view_model.dart';
|
|
import 'package:mc_gallery/features/home/views/image_carousel/image_carousel_view_model.dart';
|
|
|
|
import 'features/core/services/app_lifecycle_service.dart';
|
|
import 'features/core/services/connection_service.dart';
|
|
import 'features/core/services/overlay_service.dart';
|
|
|
|
GetIt get locate => Locator.instance();
|
|
|
|
class Locator {
|
|
static GetIt instance() => GetIt.instance;
|
|
static T locate<T extends Object>() => instance().get<T>();
|
|
|
|
static Future<void> setup() async {
|
|
final locator = instance();
|
|
|
|
_registerAPIs();
|
|
_registerViewModels();
|
|
|
|
await _registerServices(locator);
|
|
await _registerRepos(locator);
|
|
|
|
_registerSingletons();
|
|
}
|
|
|
|
static void _registerAPIs() {
|
|
instance().registerFactory(
|
|
() => UnsplashImagesApi(),
|
|
);
|
|
}
|
|
|
|
static void _registerViewModels() {
|
|
instance().registerFactory(
|
|
() => GalleryViewModel(
|
|
imagesService: ImagesService.locate,
|
|
navigationService: NavigationService.locate,
|
|
imageCacheManagerService: ImageCacheManagerService.locate,
|
|
loggingService: LoggingService.locate,
|
|
),
|
|
);
|
|
instance().registerFactory(
|
|
() => ImageCarouselViewModel(
|
|
imagesService: ImagesService.locate,
|
|
navigationService: NavigationService.locate,
|
|
loggingService: LoggingService.locate,
|
|
),
|
|
);
|
|
}
|
|
|
|
static FutureOr<void> _registerServices(GetIt it) {
|
|
it.registerLazySingleton(
|
|
() => NavigationService(
|
|
mcgRouter: McgRouter.locate,
|
|
),
|
|
);
|
|
it.registerFactory(
|
|
() => LoggingService(),
|
|
);
|
|
it.registerLazySingleton(
|
|
() => ConnectionService(
|
|
connectivity: Connectivity(),
|
|
internetConnectionChecker: InternetConnectionChecker(),
|
|
),
|
|
);
|
|
it.registerLazySingleton(
|
|
() => OverlayService(
|
|
loggingService: LoggingService.locate,
|
|
),
|
|
dispose: (param) => param.dispose(),
|
|
);
|
|
instance().registerSingleton<AppLifecycleService>(
|
|
AppLifecycleService(
|
|
loggingService: LoggingService.locate,
|
|
),
|
|
dispose: (param) async => await param.dispose(),
|
|
);
|
|
it.registerSingleton(
|
|
ImagesService(imagesApi: UnsplashImagesApi.locate, loggingService: LoggingService.locate),
|
|
signalsReady: true,
|
|
);
|
|
it.registerSingleton(
|
|
ImageCacheManagerService(
|
|
appLifecycleService: AppLifecycleService.locate,
|
|
),
|
|
);
|
|
}
|
|
|
|
static FutureOr<void> _registerRepos(GetIt locator) {}
|
|
|
|
static void _registerSingletons() {}
|
|
}
|