kopia lustrzana https://gitlab.com/mysocialportal/relatica
Move all the DI initialization to a function to be cleaner.
rodzic
762593ae24
commit
3264a0c9e3
|
@ -0,0 +1,73 @@
|
||||||
|
import 'package:logging/logging.dart';
|
||||||
|
import 'package:result_monad/result_monad.dart';
|
||||||
|
|
||||||
|
import 'data/interfaces/connections_repo_intf.dart';
|
||||||
|
import 'data/interfaces/groups_repo.intf.dart';
|
||||||
|
import 'data/interfaces/hashtag_repo_intf.dart';
|
||||||
|
import 'data/memory/memory_groups_repo.dart';
|
||||||
|
import 'data/objectbox/objectbox_cache.dart';
|
||||||
|
import 'data/objectbox/objectbox_connections_repo.dart';
|
||||||
|
import 'data/objectbox/objectbox_hashtag_repo.dart';
|
||||||
|
import 'globals.dart';
|
||||||
|
import 'models/TimelineIdentifiers.dart';
|
||||||
|
import 'services/auth_service.dart';
|
||||||
|
import 'services/connections_manager.dart';
|
||||||
|
import 'services/entry_manager_service.dart';
|
||||||
|
import 'services/gallery_service.dart';
|
||||||
|
import 'services/hashtag_service.dart';
|
||||||
|
import 'services/media_upload_attachment_helper.dart';
|
||||||
|
import 'services/notifications_manager.dart';
|
||||||
|
import 'services/secrets_service.dart';
|
||||||
|
import 'services/setting_service.dart';
|
||||||
|
import 'services/timeline_manager.dart';
|
||||||
|
|
||||||
|
final _logger = Logger('DI_Init');
|
||||||
|
|
||||||
|
Future<void> dependencyInjectionInitialization() async {
|
||||||
|
final authService = AuthService();
|
||||||
|
final secretsService = SecretsService();
|
||||||
|
final entryManagerService = EntryManagerService();
|
||||||
|
final timelineManager = TimelineManager();
|
||||||
|
final galleryService = GalleryService();
|
||||||
|
|
||||||
|
getIt.registerSingletonAsync(() async {
|
||||||
|
final service = SettingsService();
|
||||||
|
await service.initialize();
|
||||||
|
return service;
|
||||||
|
});
|
||||||
|
|
||||||
|
final objectBoxCache = await ObjectBoxCache.create();
|
||||||
|
getIt.registerSingleton<ObjectBoxCache>(objectBoxCache);
|
||||||
|
getIt.registerSingleton<IConnectionsRepo>(ObjectBoxConnectionsRepo());
|
||||||
|
getIt.registerSingleton<IHashtagRepo>(ObjectBoxHashtagRepo());
|
||||||
|
getIt.registerSingleton<IGroupsRepo>(MemoryGroupsRepo());
|
||||||
|
getIt.registerLazySingleton<ConnectionsManager>(() => ConnectionsManager());
|
||||||
|
getIt.registerLazySingleton<HashtagService>(() => HashtagService());
|
||||||
|
getIt.registerSingleton(galleryService);
|
||||||
|
getIt.registerSingleton<EntryManagerService>(entryManagerService);
|
||||||
|
getIt.registerSingleton<SecretsService>(secretsService);
|
||||||
|
getIt.registerSingleton<AuthService>(authService);
|
||||||
|
getIt.registerSingleton<TimelineManager>(timelineManager);
|
||||||
|
getIt.registerLazySingleton<MediaUploadAttachmentHelper>(
|
||||||
|
() => MediaUploadAttachmentHelper());
|
||||||
|
getIt.registerLazySingleton<NotificationsManager>(
|
||||||
|
() => NotificationsManager());
|
||||||
|
galleryService.getGalleries();
|
||||||
|
|
||||||
|
await secretsService.initialize().andThenSuccessAsync((credentials) async {
|
||||||
|
if (credentials.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final wasLoggedIn = await authService.getStoredLoginState();
|
||||||
|
if (wasLoggedIn) {
|
||||||
|
final result = await authService.signIn(credentials);
|
||||||
|
if (result.isSuccess) {
|
||||||
|
timelineManager.updateTimeline(
|
||||||
|
TimelineIdentifiers.home(), TimelineRefreshType.loadOlder);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_logger.severe('Was not logged in');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -3,32 +3,20 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:multi_trigger_autocomplete/multi_trigger_autocomplete.dart';
|
import 'package:multi_trigger_autocomplete/multi_trigger_autocomplete.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:result_monad/result_monad.dart';
|
|
||||||
|
|
||||||
import 'data/interfaces/connections_repo_intf.dart';
|
import 'di_initialization.dart';
|
||||||
import 'data/interfaces/groups_repo.intf.dart';
|
|
||||||
import 'data/interfaces/hashtag_repo_intf.dart';
|
|
||||||
import 'data/memory/memory_groups_repo.dart';
|
|
||||||
import 'data/objectbox/objectbox_cache.dart';
|
|
||||||
import 'data/objectbox/objectbox_connections_repo.dart';
|
|
||||||
import 'data/objectbox/objectbox_hashtag_repo.dart';
|
|
||||||
import 'globals.dart';
|
import 'globals.dart';
|
||||||
import 'models/TimelineIdentifiers.dart';
|
|
||||||
import 'routes.dart';
|
import 'routes.dart';
|
||||||
import 'services/auth_service.dart';
|
import 'services/auth_service.dart';
|
||||||
import 'services/connections_manager.dart';
|
import 'services/connections_manager.dart';
|
||||||
import 'services/entry_manager_service.dart';
|
import 'services/entry_manager_service.dart';
|
||||||
import 'services/gallery_service.dart';
|
import 'services/gallery_service.dart';
|
||||||
import 'services/hashtag_service.dart';
|
import 'services/hashtag_service.dart';
|
||||||
import 'services/media_upload_attachment_helper.dart';
|
|
||||||
import 'services/notifications_manager.dart';
|
import 'services/notifications_manager.dart';
|
||||||
import 'services/secrets_service.dart';
|
|
||||||
import 'services/setting_service.dart';
|
import 'services/setting_service.dart';
|
||||||
import 'services/timeline_manager.dart';
|
import 'services/timeline_manager.dart';
|
||||||
import 'utils/app_scrolling_behavior.dart';
|
import 'utils/app_scrolling_behavior.dart';
|
||||||
|
|
||||||
final _logger = Logger('Main');
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await dotenv.load(fileName: '.env');
|
await dotenv.load(fileName: '.env');
|
||||||
|
@ -41,52 +29,7 @@ void main() async {
|
||||||
print(msg);
|
print(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
final authService = AuthService();
|
dependencyInjectionInitialization();
|
||||||
final secretsService = SecretsService();
|
|
||||||
final entryManagerService = EntryManagerService();
|
|
||||||
final timelineManager = TimelineManager();
|
|
||||||
final galleryService = GalleryService();
|
|
||||||
|
|
||||||
getIt.registerSingletonAsync(() async {
|
|
||||||
final service = SettingsService();
|
|
||||||
await service.initialize();
|
|
||||||
return service;
|
|
||||||
});
|
|
||||||
|
|
||||||
final objectBoxCache = await ObjectBoxCache.create();
|
|
||||||
getIt.registerSingleton<ObjectBoxCache>(objectBoxCache);
|
|
||||||
getIt.registerSingleton<IConnectionsRepo>(ObjectBoxConnectionsRepo());
|
|
||||||
getIt.registerSingleton<IHashtagRepo>(ObjectBoxHashtagRepo());
|
|
||||||
getIt.registerSingleton<IGroupsRepo>(MemoryGroupsRepo());
|
|
||||||
getIt.registerLazySingleton<ConnectionsManager>(() => ConnectionsManager());
|
|
||||||
getIt.registerLazySingleton<HashtagService>(() => HashtagService());
|
|
||||||
getIt.registerSingleton(galleryService);
|
|
||||||
getIt.registerSingleton<EntryManagerService>(entryManagerService);
|
|
||||||
getIt.registerSingleton<SecretsService>(secretsService);
|
|
||||||
getIt.registerSingleton<AuthService>(authService);
|
|
||||||
getIt.registerSingleton<TimelineManager>(timelineManager);
|
|
||||||
getIt.registerLazySingleton<MediaUploadAttachmentHelper>(
|
|
||||||
() => MediaUploadAttachmentHelper());
|
|
||||||
getIt.registerLazySingleton<NotificationsManager>(
|
|
||||||
() => NotificationsManager());
|
|
||||||
galleryService.getGalleries();
|
|
||||||
|
|
||||||
await secretsService.initialize().andThenSuccessAsync((credentials) async {
|
|
||||||
if (credentials.isEmpty) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final wasLoggedIn = await authService.getStoredLoginState();
|
|
||||||
if (wasLoggedIn) {
|
|
||||||
final result = await authService.signIn(credentials);
|
|
||||||
if (result.isSuccess) {
|
|
||||||
timelineManager.updateTimeline(
|
|
||||||
TimelineIdentifiers.home(), TimelineRefreshType.loadOlder);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_logger.severe('Was not logged in');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
runApp(const App());
|
runApp(const App());
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue