-
Notifications
You must be signed in to change notification settings - Fork 38
/
init_dependencies.main.dart
116 lines (106 loc) · 2.38 KB
/
init_dependencies.main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
part of 'init_dependencies.dart';
final serviceLocator = GetIt.instance;
Future<void> initDependencies() async {
_initAuth();
_initBlog();
final supabase = await Supabase.initialize(
url: AppSecrets.supabaseUrl,
anonKey: AppSecrets.supabaseAnonKey,
);
Hive.defaultDirectory = (await getApplicationDocumentsDirectory()).path;
serviceLocator.registerLazySingleton(() => supabase.client);
serviceLocator.registerLazySingleton(
() => Hive.box(name: 'blogs'),
);
serviceLocator.registerFactory(() => InternetConnection());
// core
serviceLocator.registerLazySingleton(
() => AppUserCubit(),
);
serviceLocator.registerFactory<ConnectionChecker>(
() => ConnectionCheckerImpl(
serviceLocator(),
),
);
}
void _initAuth() {
// Datasource
serviceLocator
..registerFactory<AuthRemoteDataSource>(
() => AuthRemoteDataSourceImpl(
serviceLocator(),
),
)
// Repository
..registerFactory<AuthRepository>(
() => AuthRepositoryImpl(
serviceLocator(),
serviceLocator(),
),
)
// Usecases
..registerFactory(
() => UserSignUp(
serviceLocator(),
),
)
..registerFactory(
() => UserLogin(
serviceLocator(),
),
)
..registerFactory(
() => CurrentUser(
serviceLocator(),
),
)
// Bloc
..registerLazySingleton(
() => AuthBloc(
userSignUp: serviceLocator(),
userLogin: serviceLocator(),
currentUser: serviceLocator(),
appUserCubit: serviceLocator(),
),
);
}
void _initBlog() {
// Datasource
serviceLocator
..registerFactory<BlogRemoteDataSource>(
() => BlogRemoteDataSourceImpl(
serviceLocator(),
),
)
..registerFactory<BlogLocalDataSource>(
() => BlogLocalDataSourceImpl(
serviceLocator(),
),
)
// Repository
..registerFactory<BlogRepository>(
() => BlogRepositoryImpl(
serviceLocator(),
serviceLocator(),
serviceLocator(),
),
)
// Usecases
..registerFactory(
() => UploadBlog(
serviceLocator(),
),
)
..registerFactory(
() => GetAllBlogs(
serviceLocator(),
),
)
// Bloc
..registerLazySingleton(
() => BlogBloc(
uploadBlog: serviceLocator(),
getAllBlogs: serviceLocator(),
),
);
}