v2.0.5: Add typed service lookup entrypoint and tests for Arcane.service

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-06-03 19:37:14 +02:00
parent fe42eac0dc
commit cbb1a78473
7 changed files with 83 additions and 2 deletions
+3
View File
@@ -43,6 +43,9 @@ abstract class Arcane {
/// Logger is not a service and is always the singleton.
static ArcaneLogger get logger => ArcaneLogger.I;
/// Provides typed service lookups through `Arcane.service.ofType<T>(context)`.
static const ArcaneServiceLookup service = ArcaneServiceLookup();
/// Provides access to the feature flags service instance registered in ArcaneApp, or the singleton if not present.
static ArcaneFeatureFlagService get features =>
services.whereType<ArcaneFeatureFlagService>().firstOrNull ??
+17
View File
@@ -144,3 +144,20 @@ class ArcaneServiceProvider
return true;
}
}
/// Typed service lookup entrypoint for `Arcane.service`.
class ArcaneServiceLookup {
const ArcaneServiceLookup();
/// Returns a service of type `T` from the closest provider in [context].
///
/// Falls back to Arcane's built-in services when no provider instance exists.
T? ofType<T extends ArcaneService>(BuildContext context) =>
ArcaneService.ofType<T>(context);
/// Returns a service of type `T` from the closest provider in [context].
///
/// Throws an assertion error if no matching service is available.
T requiredOfType<T extends ArcaneService>(BuildContext context) =>
ArcaneService.requiredOfType<T>(context);
}