LevitScope class
A scoped dependency injection container.
LevitScope manages a registry of dependencies. Scopes can be nested; child scopes can override parent dependencies locally and automatically clean up their own resources when disposed. Dependency lookups fall back to the parent scope if the key is not found locally.
Use this class to create isolated environments for tests or modular parts of your application (e.g., authenticated vs. guest scope).
Constructors
- LevitScope.internal(String name, {LevitScope? parentScope})
- Creates a new LevitScope.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
The name of this scope, used for debugging purposes.
final
- registeredCount → int
-
The number of dependencies registered locally in this scope.
no setter
-
registeredKeys
→ List<
String> -
A list of keys for all locally registered dependencies (for debugging).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createScope(
String name) → LevitScope - Creates a new child scope that falls back to this scope for dependency resolution.
-
delete<
S> ({String? tag, bool force = false}) → bool -
Deletes an instance of type
Sfrom this scope. -
find<
S> ({String? tag}) → S -
Finds and returns the registered instance of type
S. -
findAsync<
S> ({String? tag}) → Future< S> -
Asynchronously finds and returns a registered instance of type
S. -
findOrNull<
S> ({String? tag}) → S? -
Finds and returns the registered instance of type
S, ornullif not found. -
findOrNullAsync<
S> ({String? tag}) → Future< S?> -
Asynchronously finds an instance of type
S, returningnullif not found. -
isInstantiated<
S> ({String? tag}) → bool -
Returns
trueif typeSis registered and has been instantiated. -
isRegistered<
S> ({String? tag}) → bool -
Returns
trueif typeSis registered in this scope or any parent scope. -
isRegisteredLocally<
S> ({String? tag}) → bool -
Returns
trueif typeSis registered in this specific scope. -
lazyPut<
S> (S builder(), {String? tag, bool permanent = false}) → void - Registers a lazy builder in this scope.
-
lazyPutAsync<
S> (Future< S> builder(), {String? tag, bool permanent = false}) → void - Registers an asynchronous lazy builder in this scope.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
put<
S> (S dependency, {String? tag, bool permanent = false}) → S - Registers a dependency instance in this scope.
-
putAsync<
S> (Future< S> builder(), {String? tag, bool permanent = false}) → Future<S> - Registers an instance created by an asynchronous builder.
-
putFactory<
S> (S builder(), {String? tag}) → void - Registers a factory that creates a new instance each time it is requested.
-
putFactoryAsync<
S> (Future< S> builder(), {String? tag}) → void - Registers an asynchronous factory that creates a NEW instance each time it is requested.
-
reset(
{bool force = false}) → void - Clears all instances in this scope only (does not affect parent scopes).
-
run<
R> (R callback()) → R -
Executes
callbackwithin a Zone where this scope is implicitly active. -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- zoneScopeKey → Object
-
Internal zone key used for implicit scope propagation.
final