Ls class
The primary entry point for managing dependencies and ambient scopes.
Ls provides a unified, static interface for interacting with the dependency injection system. It leverages Zone-based implicit propagation to simplify access to the current LevitScope.
// Example usage:
// Implicitly targets the active scope
final auth = Ls.find<AuthService>();
Constructors
- Ls()
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
-
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
Static Properties
- currentScope → LevitScope
-
Retrieves the current active LevitScope.
no setter
- registeredCount → int
-
The total number of dependencies registered in the current active scope.
no setter
-
registeredKeys
→ List<
String> -
A list of all registration keys (type + tag) in the current active scope.
no setter
- zoneScopeKey → Object
-
The internal Zone key used to find the active scope.
final
Static Methods
-
addMiddleware(
LevitScopeMiddleware middleware) → void - Adds a global middleware for receiving dependency injection events.
-
createScope(
String name) → LevitScope - Creates a new child scope branching from the current active scope.
-
delete<
S> ({String? tag, bool force = false}) → bool -
Removes the registration for
Sand disposes of the instance. -
find<
S> ({String? tag}) → S -
Retrieves the registered instance of type
S. -
findAsync<
S> ({String? tag}) → Future< S> -
Asynchronously retrieves the registered instance of type
S. -
findOrNull<
S> ({String? tag}) → S? -
Retrieves the registered instance of type
S, or returnsnullif not found. -
findOrNullAsync<
S> ({String? tag}) → Future< S?> -
Asynchronously retrieves the registered instance of type
S, or returnsnull. -
isInstantiated<
S> ({String? tag}) → bool -
Returns
trueif typeShas already been instantiated. -
isRegistered<
S> ({String? tag}) → bool -
Returns
trueif typeSis registered in the current or any parent scope. -
lazyPut<
S> (S builder(), {String? tag, bool permanent = false, bool isFactory = false}) → void -
Registers a
builderthat will be executed only when the dependency is first requested. -
lazyPutAsync<
S> (Future< S> builder(), {String? tag, bool permanent = false, bool isFactory = false}) → Future<S> Function() -
Registers an asynchronous
builderfor lazy instantiation. -
put<
S> (S builder(), {String? tag, bool permanent = false}) → S -
Instantiates and registers a dependency using a
builder. -
removeMiddleware(
LevitScopeMiddleware middleware) → void - Removes a DI middleware.
-
reset(
{bool force = false}) → void - Disposes of all non-permanent dependencies in the current scope.