deps_resolver.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import 'package:app_flowy/workspace/application/app/app_bloc.dart';
  2. import 'package:app_flowy/workspace/application/doc/doc_bloc.dart';
  3. import 'package:app_flowy/workspace/application/doc/share_bloc.dart';
  4. import 'package:app_flowy/workspace/application/menu/menu_bloc.dart';
  5. import 'package:app_flowy/workspace/application/menu/menu_user_bloc.dart';
  6. import 'package:app_flowy/workspace/application/trash/trash_bloc.dart';
  7. import 'package:app_flowy/workspace/application/view/view_bloc.dart';
  8. import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart';
  9. import 'package:app_flowy/workspace/domain/i_doc.dart';
  10. import 'package:app_flowy/workspace/domain/i_share.dart';
  11. import 'package:app_flowy/workspace/domain/i_trash.dart';
  12. import 'package:app_flowy/workspace/domain/i_view.dart';
  13. import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart';
  14. import 'package:app_flowy/workspace/infrastructure/i_app_impl.dart';
  15. import 'package:app_flowy/workspace/infrastructure/i_doc_impl.dart';
  16. import 'package:app_flowy/workspace/infrastructure/i_trash_impl.dart';
  17. import 'package:app_flowy/workspace/infrastructure/i_workspace_impl.dart';
  18. import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart';
  19. import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart';
  20. import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart';
  21. import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart';
  22. import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart';
  23. import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile;
  24. import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart';
  25. import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart';
  26. import 'package:get_it/get_it.dart';
  27. import 'i_share_impl.dart';
  28. import 'i_user_impl.dart';
  29. import 'i_view_impl.dart';
  30. import 'repos/share_repo.dart';
  31. class HomeDepsResolver {
  32. static Future<void> resolve(GetIt getIt) async {
  33. //
  34. getIt.registerLazySingleton<HomeStackManager>(() => HomeStackManager());
  35. getIt.registerFactoryParam<WelcomeBloc, UserProfile, void>(
  36. (user, _) => WelcomeBloc(
  37. repo: UserRepo(user: user),
  38. listener: getIt<IUserListener>(param1: user),
  39. ),
  40. );
  41. //App
  42. getIt.registerFactoryParam<IApp, String, void>((appId, _) => IAppImpl(repo: AppRepository(appId: appId)));
  43. getIt.registerFactoryParam<IAppListenr, String, void>(
  44. (appId, _) => IAppListenerhImpl(repo: AppListenerRepository(appId: appId)));
  45. //workspace
  46. getIt.registerFactoryParam<IWorkspace, UserProfile, String>(
  47. (user, workspaceId) => IWorkspaceImpl(repo: WorkspaceRepo(user: user, workspaceId: workspaceId)));
  48. getIt.registerFactoryParam<IWorkspaceListener, UserProfile, String>((user, workspaceId) =>
  49. IWorkspaceListenerImpl(repo: WorkspaceListenerRepo(user: user, workspaceId: workspaceId)));
  50. // View
  51. getIt.registerFactoryParam<IView, View, void>((view, _) => IViewImpl(repo: ViewRepository(view: view)));
  52. getIt.registerFactoryParam<IViewListener, View, void>(
  53. (view, _) => IViewListenerImpl(repo: ViewListenerRepository(view: view)));
  54. getIt.registerFactoryParam<ViewBloc, View, void>(
  55. (view, _) => ViewBloc(
  56. viewManager: getIt<IView>(param1: view),
  57. listener: getIt<IViewListener>(param1: view),
  58. ),
  59. );
  60. // Doc
  61. getIt.registerFactoryParam<IDoc, String, void>((docId, _) => IDocImpl(repo: DocRepository(docId: docId)));
  62. // User
  63. getIt.registerFactoryParam<IUser, UserProfile, void>((user, _) => IUserImpl(repo: UserRepo(user: user)));
  64. getIt.registerFactoryParam<IUserListener, UserProfile, void>((user, _) => IUserListenerImpl(user: user));
  65. //Menu Bloc
  66. getIt.registerFactoryParam<MenuBloc, UserProfile, String>(
  67. (user, workspaceId) => MenuBloc(
  68. workspaceManager: getIt<IWorkspace>(param1: user, param2: workspaceId),
  69. listener: getIt<IWorkspaceListener>(param1: user, param2: workspaceId),
  70. ),
  71. );
  72. getIt.registerFactoryParam<MenuUserBloc, UserProfile, void>(
  73. (user, _) => MenuUserBloc(getIt<IUser>(param1: user), getIt<IUserListener>(param1: user)));
  74. // App
  75. getIt.registerFactoryParam<AppBloc, App, void>(
  76. (app, _) => AppBloc(
  77. app: app,
  78. appManager: getIt<IApp>(param1: app.id),
  79. listener: getIt<IAppListenr>(param1: app.id),
  80. ),
  81. );
  82. // Doc
  83. getIt.registerFactoryParam<DocBloc, View, void>(
  84. (view, _) => DocBloc(
  85. view: view,
  86. docManager: getIt<IDoc>(param1: view.id),
  87. listener: getIt<IViewListener>(param1: view),
  88. trasnManager: getIt<ITrash>(),
  89. ),
  90. );
  91. // trash
  92. getIt.registerLazySingleton<TrashRepo>(() => TrashRepo());
  93. getIt.registerLazySingleton<TrashListenerRepo>(() => TrashListenerRepo());
  94. getIt.registerFactory<ITrash>(() => ITrashImpl(repo: getIt<TrashRepo>()));
  95. getIt.registerFactory<ITrashListener>(() => ITrashListenerImpl(repo: getIt<TrashListenerRepo>()));
  96. getIt.registerFactory<TrashBloc>(() => TrashBloc(trasnManager: getIt<ITrash>(), listener: getIt<ITrashListener>()));
  97. // share
  98. getIt.registerLazySingleton<ShareRepo>(() => ShareRepo());
  99. getIt.registerFactory<IShare>(() => IShareImpl(repo: getIt<ShareRepo>()));
  100. getIt.registerFactoryParam<DocShareBloc, View, void>(
  101. (view, _) => DocShareBloc(view: view, shareManager: getIt<IShare>()));
  102. }
  103. }