AutoInjector class abstract

Automatic Dependency Injection System, but without build_runner :)
[tag]: AutoInject instance identity.
[on]: Helps with instance registration.
[paramObservers]: List of functions that listen and transform parameters while they are being parsed when requested by the get() method.

final injector = AutoInjector();

injector.add(MyDatasource.new);

injector.get<MyDatasource>();

Constructors

AutoInjector({String? tag, List<ParamTransform> paramTransforms = const [], void on(AutoInjector injector)?})
Automatic Dependency Injection System, but without build_runner :)
[tag]: AutoInject instance identity.
[on]: Helps with instance registration.
[paramObservers]: List of functions that listen and transform parameters while they are being parsed when requested by the get() method.

factory

Properties

bindLength int
Only test
no setter
hashCode int
The hash code for this object.
no setterinherited
on → void Function(AutoInjector injector)?
Helps with instance registration
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

add<T>(Function constructor, {BindConfig<T>? config, String? key}) → void
Register a factory instance. A new instance will be generated whenever requested.
inherited
addDisposeListener(VoidCallback callback) → void
Run the callback when method dispose is called.
All the dispose callbacks are called before the injector is disposed.
addInjector(AutoInjector injector) → void
Inherit all instances and transforms from other AutoInjector object.
addInstance<T>(T instance, {BindConfig<T>? config, String? key}) → void
Register a instance. A concrete object (Not a function).
inherited
addLazySingleton<T>(Function constructor, {BindConfig<T>? config, String? key}) → void
Register a LazySingleton instance. It will generate a single instance for the duration of the application, or until manually removed.
The object will be started only when requested the first time.
inherited
addSingleton<T>(Function constructor, {BindConfig<T>? config, String? key}) → void
Register a Singleton instance. It will generate a single instance for the duration of the application, or until manually removed.
The object will be started as soon as it is registered.
inherited
call<T>({ParamTransform? transform, String? key}) → T
Request an instance by Type
transform: Transform a param. This can be used for example to replace an instance with a mock in tests.
When key is provided it will search the instance that have the same key
inherited
commit() → void
Informs the container that the additions are finished and the injector is ready to be used.
This command starts the singletons.
dispose([void instanceCallback(dynamic instance)?]) → void
Remove all the binds and turns the injector uncommitted
disposeInjectorByTag(String injectorTag, [void instanceCallback(dynamic instance)?]) → void
Find the injector by injectorTag in the layers tree and execute "dispose()" on it
disposeRecursive() → void
Execute "dispose()" in all the injectors from this layers tree
disposeSingleton<T>({String? key}) → T?
Removes the singleton instance.
This does not remove it from the registry tree.
When key is provided it will search the instance that have the same key
get<T>({ParamTransform? transform, String? key}) → T
Request an instance by Type
transform : Transform a param. This can be used for example to replace an instance with a mock in tests.
When key is provided it will search the instance that have the same key
inherited
getNotifier<T>({String? key}) → dynamic
Request an notifier property by Type
When key is provided it will search the instance that have the same key
inherited
isAdded<T>({String? key}) bool
Checks if the instance record exists.
When key is provided it will search the instance that have the same key
isInstantiateSingleton<T>({String? key}) bool
checks if the instance registration is as singleton.
When key is provided it will search the instance that have the same key
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeDisposeListener(VoidCallback callback) → void
Remove the callback previous included using addDisposeListener.
If the callback was NOT included previously using addDisposeListener it will not do anything.
replaceInstance<T>(T instance, {String? key}) → void
Replaces an instance record with a concrete instance.
This function should only be used for unit testing.
Any other use is discouraged.
When key is provided it will search the instance that have the same key
toString() String
A string representation of this object.
inherited
tryGet<T>({ParamTransform? transform, String? key}) → T?
Request an instance by Type that when throwing an exception returns null.
transform: Transform a param. This can be used for example to replace an instance with a mock in tests.
When key is provided it will search the instance that have the same key
uncommit() → void
remove commit

Operators

operator ==(Object other) bool
The equality operator.
inherited