From 304c6c8094aeafb61f76d43afc006e9cc263894f Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Tue, 29 Apr 2025 17:09:55 +0200 Subject: [PATCH] Re-add service locators. They should be called as: ArcaneService.of(context) Signed-off-by: Hans Kokx --- lib/src/providers/service_provider.dart | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/src/providers/service_provider.dart b/lib/src/providers/service_provider.dart index 7326e5b..3a0cb21 100644 --- a/lib/src/providers/service_provider.dart +++ b/lib/src/providers/service_provider.dart @@ -157,4 +157,31 @@ extension ServiceProviderExtension on BuildContext { } /// An abstract class representing a service in the Arcane architecture. -abstract class ArcaneService with ChangeNotifier {} +/// +/// Classes that extend `ArcaneService` can use `ChangeNotifier` functionality +/// to notify listeners of changes. Services are typically registered in +/// `ArcaneServiceProvider` and can be accessed using the `service` +/// method on `BuildContext`. +abstract class ArcaneService with ChangeNotifier { + /// Retrieves a service of the specified type from the context. + /// + /// Returns null if no service of type `T` is found. + /// + /// Example: + /// ```dart + /// final myService = ArcaneService.of(context); + /// ``` + static T? of(BuildContext context) => + context.service(); + + /// Retrieves a service of the specified type from the context. + /// + /// Throws an assertion error if no service of type `T` is found. + /// + /// Example: + /// ```dart + /// final myService = ArcaneService.requiredOf(context); + /// ``` + static T requiredOf(BuildContext context) => + context.requiredService(); +}