ServiceScope class
A child scope that inherits registrations from a parent ServiceLocator but maintains its own instance cache for ServiceLifetime.scoped services.
Create a scope when entering a feature area (e.g. a screen) and call dispose when leaving it. All PkDisposable scoped instances are cleaned up automatically.
final scope = ServiceScope.of(ServiceLocator.instance);
// Resolves scoped instances independently from the parent:
final bloc = scope.get<FormBloc>();
// Clean up when done (e.g. in State.dispose):
await scope.dispose();
Constructors
- ServiceScope.of(ServiceLocator parent)
-
Creates a ServiceScope whose registrations are inherited from
parent.factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dispose(
) → Future< void> - Disposes all PkDisposable scoped instances and marks the scope as closed.
-
get<
T extends Object> () → T -
Resolves the service registered for type
T. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited