Skip to content

Commit

Permalink
Merge pull request #8 from AyushBherwani1998/feature/di
Browse files Browse the repository at this point in the history
adds dependency injection
  • Loading branch information
AyushBherwani1998 committed Aug 2, 2023
2 parents 0bcb45b + 65c4b73 commit e3e7bb3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ ignore:
- '**/entities/'
- 'lib/core/error/'
- 'lib/core/usecases/'
- 'dependency_injection.dart'
29 changes: 29 additions & 0 deletions lib/dependency_injection.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:dio/dio.dart';
import 'package:get_it/get_it.dart';
import 'package:unplash_sample/features/home/data/datasources/unsplash_remote_datasource.dart';
import 'package:unplash_sample/features/home/data/repositories/unsplash_repository_impl.dart';
import 'package:unplash_sample/features/home/domain/repositories/unsplash_repository.dart';
import 'package:unplash_sample/features/home/domain/usecases/fetch_images.dart';
import 'package:unplash_sample/features/home/presentation/bloc/unsplash_image_bloc.dart';

class DependencyInjection {
DependencyInjection._();

static GetIt get getIt => GetIt.instance;

static void initialize() {
getIt.registerFactory(() => UnsplashImageBloc(getIt()));

getIt.registerLazySingleton(() => FetchImages(repository: getIt()));

getIt.registerLazySingleton<UnsplashRepository>(
() => UnsplashRepositoryImpl(getIt()),
);

getIt.registerLazySingleton<UnsplashRemoteDataSource>(
() => UnsplashRemoteDataSourceImpl(getIt()),
);

getIt.registerLazySingleton(() => Dio());
}
}
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:unplash_sample/dependency_injection.dart';

void main() {
DependencyInjection.initialize();
runApp(const MyApp());
}

Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.2.0"
get_it:
dependency: "direct main"
description:
name: get_it
sha256: "529de303c739fca98cd7ece5fca500d8ff89649f1bb4b4e94fb20954abcd7468"
url: "https://pub.dev"
source: hosted
version: "7.6.0"
glob:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies:
dio: ^5.3.0
equatable: ^2.0.5
flutter_dotenv: ^5.1.0
get_it: ^7.6.0
go_router: ^10.0.0
mocktail: ^0.3.0

Expand Down

0 comments on commit e3e7bb3

Please sign in to comment.