ControlFactory class
The core implementation of the service locator and dependency injection container.
ControlFactory manages the lifecycle of objects, including their registration,
creation (through factories), retrieval, and disposal.
While you can create and manage your own ControlFactory instances, most applications
will use the default global instance accessible via Control.factory.
The factory stores objects in two main ways:
- As singleton instances (
_items): These are created once and reused. - As factory functions (
_factory): These are functions that know how to create a new instance of an object when needed.
The factory is initialized via the initialize method, which is typically called by Control.initControl.
- Mixed-in types
- Available extensions
Properties
- debug ↔ bool
-
Runtime debug value. Default value is
false.getter/setter pair - hashCode → int
-
The hash code for this object.
no setterinherited
- isInitialized → bool
-
Checks if Factory is initialized.
Use onReady to listen initialize completion.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
add<
T> ({Type? key, required InitFactory< T> init}) → void - Adds Factory for later use - Control.init or Control.get.
-
call<
T> ({dynamic key, dynamic args, bool withInjector = true}) → T? - Callable class - get.
-
clear(
) → bool -
Clears whole Factory - all stored objects, initializers and injector.
Also
BaseLocalization, ControlBroadcast and ControlRoute is removed and cleared/disposed. -
contains(
dynamic value) → bool - Checks if key/type/object is in Factory.
-
containsItem<
T> ({dynamic key}) → bool -
Checks if given
keyis already initialized in Factory. Looks just to store. (factories are not included) -
containsKey(
dynamic key) → bool -
Checks if given
keyis in Factory. Looks to store and factories. -
containsType<
T> () → bool - Checks if Type is in Factory. Looks to store and initializers.
-
dispose(
) → void -
Releases resources used by the object.
override
-
disposeWith(
DisposeObserver observer) → void -
Available on Disposable, provided by the DisposableExt extension
Register for dispose with givenobserver. -
findInitializer<
T> ([Type? key]) → InitFactory< T?> ? - Finds and returns a registered InitFactory for a given type.
-
get<
T> ({dynamic key, dynamic args, bool withInjector = true}) → T? -
Retrieves an object of type
Tfrom the factory. -
init<
T> ({Type? key, dynamic args, bool forceInit = true}) → T? -
Creates a new instance of an object of type
Tusing a registered factory. -
initialize(
{Map? entries, Map< Type, InitFactory> ? factories, Future initAsync()?}) → bool - Initializes the factory with a set of entries, factories, and an optional async setup task.
-
keyOf<
T> ({dynamic key, dynamic value}) → dynamic - Determines the key to use for storing or retrieving an object in the factory.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onReady(
) → Future< void> - A future that completes when the factory has finished its asynchronous initialization.
-
printDebugStore(
{bool items = true, bool initializers = true}) → void -
registerModule(
ControlModule module, {bool includeSubModules = false}) → void - Loads module into this factory.
-
remove<
T> ({dynamic key, bool dispose = false}) → int -
Removes specific object with given
keyor by Type from ControlFactory. When givenkeyis null, then key isT- check ControlFactory.keyOf for more info. If object of givenkeyis not found, then all instances ofTare removed. Setdisposeto dispose removed object/s. -
removeInitializer(
Type key) → bool -
Removes initializer of given
key. Returns true if initializer is removed. -
resolve<
T> (dynamic source, {dynamic key, dynamic args, T? defaultValue()?}) → T? -
Executes sequence of functions to retrieve expected object.
Look up in
sourcefor item via Parse.getArg and if object is not found then ControlFactory.get is executed. After all,defaultValueis used. Returns object fromsourcethen ControlFactory thendefaultValue. -
set<
T> ({dynamic key, required dynamic value}) → dynamic -
Stores
valuewith givenkeyin ControlFactory. When givenkeyis null, then key isTor generated from Type of givenvalue- check ControlFactory.keyOf for more info. Object with samekeypreviously stored in factory is overridden. Returnskeyof the storedvalue. -
swap<
T> ({dynamic key, required dynamic value, bool dispose = false}) → void -
Swaps
valuein Factory by givenkeyor Type. When givenkeyis null, then key isT- check ControlFactory.keyOf for more info. -
swapInitializer<
T> (InitFactory< T> initializer) → void - Swaps initializers in Factory. Basically calls ControlFactory.removeInitializer and ControlFactory.add.
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited