deps_resolver.dart 6.3 KB

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