deps_resolver.dart 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import 'package:app_flowy/core/network_monitor.dart';
  2. import 'package:app_flowy/user/application/user_listener.dart';
  3. import 'package:app_flowy/user/application/user_service.dart';
  4. import 'package:app_flowy/workspace/application/app/prelude.dart';
  5. import 'package:app_flowy/workspace/application/doc/prelude.dart';
  6. import 'package:app_flowy/workspace/application/grid/prelude.dart';
  7. import 'package:app_flowy/workspace/application/trash/prelude.dart';
  8. import 'package:app_flowy/workspace/application/user/prelude.dart';
  9. import 'package:app_flowy/workspace/application/workspace/prelude.dart';
  10. import 'package:app_flowy/workspace/application/edit_pannel/edit_pannel_bloc.dart';
  11. import 'package:app_flowy/workspace/application/view/prelude.dart';
  12. import 'package:app_flowy/workspace/application/menu/prelude.dart';
  13. import 'package:app_flowy/user/application/prelude.dart';
  14. import 'package:app_flowy/user/presentation/router.dart';
  15. import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
  16. import 'package:app_flowy/workspace/presentation/home/menu/menu.dart';
  17. import 'package:flowy_sdk/protobuf/flowy-folder/app.pb.dart';
  18. import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
  19. import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart';
  20. import 'package:fluttertoast/fluttertoast.dart';
  21. import 'package:get_it/get_it.dart';
  22. class DependencyResolver {
  23. static Future<void> resolve(GetIt getIt) async {
  24. _resolveUserDeps(getIt);
  25. _resolveHomeDeps(getIt);
  26. _resolveFolderDeps(getIt);
  27. _resolveDocDeps(getIt);
  28. _resolveGridDeps(getIt);
  29. }
  30. }
  31. void _resolveUserDeps(GetIt getIt) {
  32. getIt.registerFactory<AuthService>(() => AuthService());
  33. getIt.registerFactory<AuthRouter>(() => AuthRouter());
  34. getIt.registerFactory<SignInBloc>(() => SignInBloc(getIt<AuthService>()));
  35. getIt.registerFactory<SignUpBloc>(() => SignUpBloc(getIt<AuthService>()));
  36. getIt.registerFactory<SplashRoute>(() => SplashRoute());
  37. getIt.registerFactory<EditPannelBloc>(() => EditPannelBloc());
  38. getIt.registerFactory<SplashBloc>(() => SplashBloc());
  39. getIt.registerLazySingleton<NetworkListener>(() => NetworkListener());
  40. }
  41. void _resolveHomeDeps(GetIt getIt) {
  42. getIt.registerSingleton(FToast());
  43. getIt.registerSingleton(MenuSharedState());
  44. getIt.registerFactoryParam<UserListener, UserProfile, void>(
  45. (user, _) => UserListener(userProfile: user),
  46. );
  47. //
  48. getIt.registerLazySingleton<HomeStackManager>(() => HomeStackManager());
  49. getIt.registerFactoryParam<WelcomeBloc, UserProfile, void>(
  50. (user, _) => WelcomeBloc(
  51. userService: UserService(userId: user.id),
  52. userWorkspaceListener: UserWorkspaceListener(userProfile: user),
  53. ),
  54. );
  55. // share
  56. getIt.registerLazySingleton<ShareService>(() => ShareService());
  57. getIt.registerFactoryParam<DocShareBloc, View, void>(
  58. (view, _) => DocShareBloc(view: view, service: getIt<ShareService>()));
  59. }
  60. void _resolveFolderDeps(GetIt getIt) {
  61. //workspace
  62. getIt.registerFactoryParam<WorkspaceListener, UserProfile, String>(
  63. (user, workspaceId) => WorkspaceListener(user: user, workspaceId: workspaceId));
  64. // View
  65. getIt.registerFactoryParam<ViewListener, View, void>(
  66. (view, _) => ViewListener(view: view),
  67. );
  68. getIt.registerFactoryParam<ViewBloc, View, void>(
  69. (view, _) => ViewBloc(
  70. view: view,
  71. service: ViewService(),
  72. listener: getIt<ViewListener>(param1: view),
  73. ),
  74. );
  75. //Menu
  76. getIt.registerFactoryParam<MenuBloc, UserProfile, String>(
  77. (user, workspaceId) => MenuBloc(
  78. workspaceId: workspaceId,
  79. listener: getIt<WorkspaceListener>(param1: user, param2: workspaceId),
  80. ),
  81. );
  82. getIt.registerFactoryParam<MenuUserBloc, UserProfile, void>(
  83. (user, _) => MenuUserBloc(user),
  84. );
  85. //User
  86. getIt.registerFactoryParam<SettingsUserViewBloc, UserProfile, void>(
  87. (user, _) => SettingsUserViewBloc(user),
  88. );
  89. // App
  90. getIt.registerFactoryParam<AppBloc, App, void>(
  91. (app, _) => AppBloc(
  92. app: app,
  93. appService: AppService(appId: app.id),
  94. appListener: AppListener(appId: app.id),
  95. ),
  96. );
  97. // trash
  98. getIt.registerLazySingleton<TrashService>(() => TrashService());
  99. getIt.registerLazySingleton<TrashListener>(() => TrashListener());
  100. getIt.registerFactory<TrashBloc>(
  101. () => TrashBloc(
  102. service: getIt<TrashService>(),
  103. listener: getIt<TrashListener>(),
  104. ),
  105. );
  106. }
  107. void _resolveDocDeps(GetIt getIt) {
  108. // Doc
  109. getIt.registerFactoryParam<DocumentBloc, View, void>(
  110. (view, _) => DocumentBloc(
  111. view: view,
  112. service: DocumentService(),
  113. listener: getIt<ViewListener>(param1: view),
  114. trashService: getIt<TrashService>(),
  115. ),
  116. );
  117. }
  118. void _resolveGridDeps(GetIt getIt) {
  119. // Grid
  120. getIt.registerFactoryParam<GridBloc, View, void>(
  121. (view, _) => GridBloc(view: view),
  122. );
  123. getIt.registerFactoryParam<GridHeaderBloc, String, GridFieldCache>(
  124. (gridId, fieldCache) => GridHeaderBloc(
  125. gridId: gridId,
  126. fieldCache: fieldCache,
  127. ),
  128. );
  129. getIt.registerFactoryParam<FieldActionSheetBloc, GridFieldCellContext, void>(
  130. (data, _) => FieldActionSheetBloc(
  131. field: data.field,
  132. fieldService: FieldService(gridId: data.gridId, fieldId: data.field.id),
  133. ),
  134. );
  135. getIt.registerFactoryParam<TextCellBloc, GridCellContext, void>(
  136. (context, _) => TextCellBloc(
  137. cellContext: context,
  138. ),
  139. );
  140. getIt.registerFactoryParam<SelectOptionCellBloc, GridSelectOptionCellContext, void>(
  141. (context, _) => SelectOptionCellBloc(
  142. cellContext: context,
  143. ),
  144. );
  145. getIt.registerFactoryParam<NumberCellBloc, GridCellContext, void>(
  146. (context, _) => NumberCellBloc(
  147. cellContext: context,
  148. ),
  149. );
  150. getIt.registerFactoryParam<DateCellBloc, GridDateCellContext, void>(
  151. (context, _) => DateCellBloc(
  152. cellContext: context,
  153. ),
  154. );
  155. getIt.registerFactoryParam<CheckboxCellBloc, GridCellContext, void>(
  156. (cellData, _) => CheckboxCellBloc(
  157. service: CellService(),
  158. cellContext: cellData,
  159. ),
  160. );
  161. getIt.registerFactoryParam<GridPropertyBloc, String, GridFieldCache>(
  162. (gridId, cache) => GridPropertyBloc(gridId: gridId, fieldCache: cache),
  163. );
  164. }