deps_resolver.dart 5.9 KB

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