mucke/lib/injection_container.dart

117 lines
3.9 KiB
Dart
Raw Normal View History

2020-12-08 20:54:41 +01:00
import 'package:audio_service/audio_service.dart';
import 'package:device_info/device_info.dart';
2020-05-27 21:54:33 +02:00
import 'package:flutter_audio_query/flutter_audio_query.dart';
import 'package:get_it/get_it.dart';
2020-12-13 12:37:08 +01:00
import 'package:just_audio/just_audio.dart' as ja;
2020-05-27 21:54:33 +02:00
import 'domain/repositories/audio_repository.dart';
import 'domain/repositories/music_data_repository.dart';
2020-12-21 11:50:46 +01:00
import 'domain/repositories/persistent_player_state_repository.dart';
import 'domain/repositories/settings_repository.dart';
2020-05-27 21:54:33 +02:00
import 'presentation/state/audio_store.dart';
import 'presentation/state/music_data_store.dart';
import 'presentation/state/navigation_store.dart';
import 'system/audio/audio_handler.dart';
2020-10-21 20:58:55 +02:00
import 'system/audio/audio_manager.dart';
import 'system/audio/audio_manager_contract.dart';
2020-12-13 12:37:08 +01:00
import 'system/audio/audio_player_contract.dart';
import 'system/audio/audio_player_impl.dart';
import 'system/audio/queue_generator.dart';
2020-05-27 21:54:33 +02:00
import 'system/datasources/local_music_fetcher.dart';
import 'system/datasources/local_music_fetcher_contract.dart';
2020-12-30 20:09:04 +01:00
import 'system/datasources/moor_database.dart';
2020-05-27 21:54:33 +02:00
import 'system/datasources/music_data_source_contract.dart';
2020-12-21 11:50:46 +01:00
import 'system/datasources/player_state_data_source.dart';
import 'system/datasources/settings_data_source.dart';
2020-05-27 21:54:33 +02:00
import 'system/repositories/audio_repository_impl.dart';
import 'system/repositories/music_data_repository_impl.dart';
2020-12-21 11:50:46 +01:00
import 'system/repositories/persistent_player_state_repository_impl.dart';
import 'system/repositories/settings_repository_impl.dart';
2020-05-27 21:54:33 +02:00
final GetIt getIt = GetIt.instance;
Future<void> setupGetIt() async {
2020-06-03 20:32:59 +02:00
print('setupGetIt');
2020-05-27 21:54:33 +02:00
// stores
getIt.registerFactory<MusicDataStore>(
() {
final musicDataStore = MusicDataStore(
musicDataRepository: getIt(),
settingsRepository: getIt(),
2020-05-27 21:54:33 +02:00
);
return musicDataStore;
},
);
getIt.registerFactory<AudioStore>(
() {
final audioStore = AudioStore(
audioRepository: getIt(),
2020-12-21 11:50:46 +01:00
persistentPlayerStateRepository: getIt(),
2020-05-27 21:54:33 +02:00
);
return audioStore;
},
);
getIt.registerFactory<NavigationStore>(
() {
final navigationStore = NavigationStore();
return navigationStore;
},
);
// repositories
getIt.registerLazySingleton<MusicDataRepository>(
() => MusicDataRepositoryImpl(
2020-12-30 18:28:16 +01:00
getIt(),
getIt(),
2020-05-27 21:54:33 +02:00
),
);
getIt.registerLazySingleton<AudioRepository>(
() => AudioRepositoryImpl(
getIt(),
),
);
2020-12-21 11:50:46 +01:00
getIt.registerLazySingleton<PlayerStateRepository>(
() => PlayerStateRepositoryImpl(getIt()),
);
getIt.registerLazySingleton<SettingsRepository>(() => SettingsRepositoryImpl(getIt()));
2020-05-27 21:54:33 +02:00
// data sources
2020-12-30 20:09:04 +01:00
final MoorDatabase moorDatabase = MoorDatabase();
getIt.registerLazySingleton<MusicDataSource>(() => moorDatabase.musicDataDao);
getIt.registerLazySingleton<PlayerStateDataSource>(() => moorDatabase.playerStateDao);
getIt.registerLazySingleton<SettingsDataSource>(() => moorDatabase.settingsDao);
2020-05-27 21:54:33 +02:00
getIt.registerLazySingleton<LocalMusicFetcher>(
() => LocalMusicFetcherImpl(
getIt(),
getIt(),
getIt(),
2020-05-27 21:54:33 +02:00
),
);
2020-12-08 20:54:41 +01:00
getIt.registerLazySingleton<AudioManager>(() => AudioManagerImpl(getIt()));
2020-12-13 12:37:08 +01:00
final AudioPlayer audioPlayer = AudioPlayerImpl(
ja.AudioPlayer(),
QueueGenerator(getIt()),
);
getIt.registerLazySingleton<AudioPlayer>(() => audioPlayer);
2020-12-08 20:54:41 +01:00
final _audioHandler = await AudioService.init(
2020-12-21 11:50:46 +01:00
builder: () => MyAudioHandler(getIt(), getIt(), getIt()),
2020-12-13 12:37:08 +01:00
config: AudioServiceConfig(
androidNotificationChannelName: 'mucke',
androidEnableQueue: true,
),
);
2020-12-08 20:54:41 +01:00
getIt.registerLazySingleton<AudioHandler>(() => _audioHandler);
2020-05-27 21:54:33 +02:00
2020-12-13 12:37:08 +01:00
getIt.registerLazySingleton<QueueGenerator>(() => QueueGenerator(getIt()));
2020-05-27 21:54:33 +02:00
// external
2020-12-13 12:37:08 +01:00
getIt.registerFactory<ja.AudioPlayer>(() => ja.AudioPlayer());
2020-05-27 21:54:33 +02:00
getIt.registerLazySingleton<FlutterAudioQuery>(() => FlutterAudioQuery());
getIt.registerLazySingleton<DeviceInfoPlugin>(() => DeviceInfoPlugin());
2020-05-27 21:54:33 +02:00
}