AutoInjector class Null safety
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 theget()
method.
factory
Properties
- bindLength → int
-
Only test
read-only
- hashCode → int
-
The hash code for this object.
read-onlyinherited
- on → (void Function(AutoInjector injector)?)
-
Helps with instance registration
final
- runtimeType → Type
-
A representation of the runtime type of the object.
read-onlyinherited
Methods
-
add<
T> (Function constructor, {String? tag, DisposeCallback< T> ? onDispose, NotifierCallback<T> ? notifier}) → void - Register a factory instance. A new instance will be generated whenever requested.
-
addInjector(
AutoInjector injector) → void - Inherit all instances and transforms from other AutoInjector object.
-
addInstance<
T> (T instance, {String? tag, DisposeCallback< T> ? onDispose, NotifierCallback<T> ? notifier}) → void - Register a instance. A concrete object (Not a function).
-
addLazySingleton<
T> (Function constructor, {String? tag, DisposeCallback< T> ? onDispose, NotifierCallback<T> ? notifier}) → 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. -
addSingleton<
T> (Function constructor, {String? tag, DisposeCallback< T> ? onDispose, NotifierCallback<T> ? notifier}) → 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. -
call<
T> ({ParamTransform? transform}) → 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. -
commit(
) → void -
Informs the container that the additions
are finished and the injector is ready to be used.
This command starts the singletons. -
disposeSingleton<
T> () → T? -
Removes the singleton instance.
This does not remove it from the registry tree. -
disposeSingletonsByTag(
String tag, {void onRemoved(dynamic instance)?}) → void -
Removes singleton instances by tag.
This does not remove it from the registry tree. -
get<
T> ({ParamTransform? transform}) → 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. -
getNotifier<
T> () → dynamic - Request an notifier propertie by Type
-
hasTag(
String tag) → bool - checks if there is any instance registered with a tag
-
isAdded<
T> () → bool - Checks if the instance record exists.
-
isInstantiateSingleton<
T> () → bool - checks if the instance registration is as singleton.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited
-
removeAll(
) → void - Remove all regiters
-
removeByTag(
String tag) → void -
Removes registers by tag.
-
replaceInstance<
T> (T instance) → void -
Replaces an instance record with a concrete instance.
This function should only be used for unit testing.
Any other use is discouraged. -
toString(
) → String -
A string representation of this object.
inherited
-
tryGet<
T> ({ParamTransform? transform}) → 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. -
uncommit(
) → void - remove commit
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited