deps_resolver.dart 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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_doc_impl.dart';
  15. import 'package:app_flowy/workspace/infrastructure/i_trash_impl.dart';
  16. import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart';
  17. import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart';
  18. import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart';
  19. import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart';
  20. import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart';
  21. import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart';
  22. import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart';
  23. import 'package:get_it/get_it.dart';
  24. import 'i_share_impl.dart';
  25. import 'i_user_impl.dart';
  26. import 'i_view_impl.dart';
  27. import 'repos/share_repo.dart';
  28. class HomeDepsResolver {
  29. static Future<void> resolve(GetIt getIt) async {
  30. //
  31. getIt.registerLazySingleton<HomeStackManager>(() => HomeStackManager());
  32. getIt.registerFactoryParam<WelcomeBloc, UserProfile, void>(
  33. (user, _) => WelcomeBloc(
  34. repo: UserRepo(user: user),
  35. listener: getIt<IUserListener>(param1: user),
  36. ),
  37. );
  38. //workspace
  39. getIt.registerFactoryParam<WorkspaceListener, UserProfile, String>(
  40. (user, workspaceId) => WorkspaceListener(repo: WorkspaceListenerRepo(user: user, workspaceId: workspaceId)));
  41. // View
  42. getIt.registerFactoryParam<IView, View, void>((view, _) => IViewImpl(repo: ViewRepository(view: view)));
  43. getIt.registerFactoryParam<IViewListener, View, void>(
  44. (view, _) => IViewListenerImpl(repo: ViewListenerRepository(view: view)));
  45. getIt.registerFactoryParam<ViewBloc, View, void>(
  46. (view, _) => ViewBloc(
  47. viewManager: getIt<IView>(param1: view),
  48. listener: getIt<IViewListener>(param1: view),
  49. ),
  50. );
  51. // Doc
  52. getIt.registerFactoryParam<IDoc, String, void>((docId, _) => IDocImpl(repo: DocRepository(docId: docId)));
  53. // User
  54. getIt.registerFactoryParam<IUser, UserProfile, void>((user, _) => IUserImpl(repo: UserRepo(user: user)));
  55. getIt.registerFactoryParam<IUserListener, UserProfile, void>((user, _) => IUserListenerImpl(user: user));
  56. //Menu Bloc
  57. getIt.registerFactoryParam<MenuBloc, UserProfile, String>(
  58. (user, workspaceId) => MenuBloc(
  59. repo: WorkspaceRepo(user: user, workspaceId: workspaceId),
  60. listener: getIt<WorkspaceListener>(param1: user, param2: workspaceId),
  61. ),
  62. );
  63. getIt.registerFactoryParam<MenuUserBloc, UserProfile, void>(
  64. (user, _) => MenuUserBloc(getIt<IUser>(param1: user), getIt<IUserListener>(param1: user)));
  65. // App
  66. getIt.registerFactoryParam<AppBloc, App, void>(
  67. (app, _) => AppBloc(
  68. app: app,
  69. repo: AppRepository(appId: app.id),
  70. listener: AppListenerRepository(appId: app.id),
  71. ),
  72. );
  73. // Doc
  74. getIt.registerFactoryParam<DocBloc, View, void>(
  75. (view, _) => DocBloc(
  76. view: view,
  77. docManager: getIt<IDoc>(param1: view.id),
  78. listener: getIt<IViewListener>(param1: view),
  79. trasnManager: getIt<ITrash>(),
  80. ),
  81. );
  82. // trash
  83. getIt.registerLazySingleton<TrashRepo>(() => TrashRepo());
  84. getIt.registerLazySingleton<TrashListenerRepo>(() => TrashListenerRepo());
  85. getIt.registerFactory<ITrash>(() => ITrashImpl(repo: getIt<TrashRepo>()));
  86. getIt.registerFactory<ITrashListener>(() => ITrashListenerImpl(repo: getIt<TrashListenerRepo>()));
  87. getIt.registerFactory<TrashBloc>(() => TrashBloc(trasnManager: getIt<ITrash>(), listener: getIt<ITrashListener>()));
  88. // share
  89. getIt.registerLazySingleton<ShareRepo>(() => ShareRepo());
  90. getIt.registerFactory<IShare>(() => IShareImpl(repo: getIt<ShareRepo>()));
  91. getIt.registerFactoryParam<DocShareBloc, View, void>(
  92. (view, _) => DocShareBloc(view: view, shareManager: getIt<IShare>()));
  93. }
  94. }