Skip to content

Commit

Permalink
feat(cat-voices): expose restart dependencies method (#1424)
Browse files Browse the repository at this point in the history
* feat: expose restart dependencies method

* refactor: reorder bootstrap test functions
  • Loading branch information
damian-molinski authored Dec 19, 2024
1 parent 3102a63 commit 9533da9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
15 changes: 14 additions & 1 deletion catalyst_voices/apps/voices/lib/configs/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Future<void> _doBootstrapAndRun(BootstrapWidgetBuilder builder) async {
await _runApp(app);
}

@visibleForTesting
GoRouter buildAppRouter({
String? initialLocation,
}) {
Expand All @@ -85,6 +86,18 @@ GoRouter buildAppRouter({
);
}

@visibleForTesting
Future<void> registerDependencies() async {
if (!Dependencies.instance.isInitialized) {
await Dependencies.instance.init();
}
}

@visibleForTesting
Future<void> restartDependencies() async {
await Dependencies.instance.reset;
}

/// Initializes the application before it can be run. Should setup all
/// the things which are necessary before the actual app is run,
/// either via [runApp] or injected into a test environment during
Expand All @@ -102,7 +115,7 @@ Future<BootstrapArgs> bootstrap({
GoRouter.optionURLReflectsImperativeAPIs = true;
setPathUrlStrategy();

await Dependencies.instance.init();
await registerDependencies();

// Key derivation needs to be initialized before it can be used
await CatalystKeyDerivation.init();
Expand Down
13 changes: 13 additions & 0 deletions catalyst_voices/apps/voices/lib/dependency/dependencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,26 @@ import 'package:catalyst_voices_shared/catalyst_voices_shared.dart';
final class Dependencies extends DependencyProvider {
static final Dependencies instance = Dependencies._();

bool _isInitialized = false;

Dependencies._();

Future<void> init() async {
DependencyProvider.instance = this;
_registerServices();
_registerRepositories();
_registerBlocsWithDependencies();

_isInitialized = true;
}

bool get isInitialized => _isInitialized;

@override
Future<void> get reset {
return super.reset.whenComplete(() {
_isInitialized = false;
});
}

void _registerBlocsWithDependencies() {
Expand Down

0 comments on commit 9533da9

Please sign in to comment.