mirror of
https://github.com/hanskokx/arcane_framework.git
synced 2026-05-14 10:29:06 +02:00
Re-add service locators. They should be called as:
ArcaneService.of<MyService>(context) Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -157,4 +157,31 @@ extension ServiceProviderExtension on BuildContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An abstract class representing a service in the Arcane architecture.
|
/// 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<MyService>(context);
|
||||||
|
/// ```
|
||||||
|
static T? of<T extends ArcaneService>(BuildContext context) =>
|
||||||
|
context.service<T>();
|
||||||
|
|
||||||
|
/// 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<MyService>(context);
|
||||||
|
/// ```
|
||||||
|
static T requiredOf<T extends ArcaneService>(BuildContext context) =>
|
||||||
|
context.requiredService<T>();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user