Injector class
A powerful static Dependency Injection container for managing instances.
Provides support for:
put
,lazyPut
,find
,delete
, etc.- Auto-dispose lifecycle
- Scoped and tagged instances
- Logging and testing overrides
Constructors
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
- enableLogs ↔ bool
-
Enables logging for DI operations.
getter/setter pair
- onEvent ↔ InjectorHook?
-
Optional external hook to listen to internal Injector events.
getter/setter pair
Static Methods
-
autoDisposePut<
T> (T instance) → void - Registers an instance that will automatically be disposed via disposeAll.
-
debugPrintDependencies(
) → void - Prints all currently registered instances, factories and tagged instances.
-
delete<
T> () → void - Removes an instance and its factory, and disposes it if applicable.
-
deleteTagged<
T> (String tag) → void - Deletes a tagged instance and disposes it if needed.
-
disposeAll(
) → void - Disposes all auto-disposable instances.
-
disposeScope(
String scope) → void -
Disposes all instances within the given
scope
. -
find<
T> () → T -
Retrieves the registered instance of type
T
, or creates one via factory. -
findTagged<
T> (String tag) → T -
Finds an instance registered with a given
tag
. -
getOrNull<
T> () → T? - Attempts to find the instance or create it; returns null if not found.
-
isRegistered<
T> () → bool -
Returns true if an instance or factory of type
T
is registered. -
lazyPut<
T> (T builder()) → void - Registers a factory function that creates an instance lazily when needed.
-
override<
T> (T instance) → void - Overrides an existing instance. Useful for testing/mocking.
-
put<
T> (T instance) → T - Registers an already created instance for the given type.
-
putAsync<
T> (Future< T> builder()) → Future<void> - Registers an instance asynchronously using a future-based builder.
-
putScoped<
T> (T instance, String scope) → void -
Registers an instance under a specific named
scope
. -
putTagged<
T> (T instance, String tag) → void -
Registers an instance under a specific
tag
. -
reset(
) → void - Disposes and clears all registered instances, factories, scopes and tags.