GetIt class
Very simple and easy to use service locator You register your object creation or an instance of an object with registerFactory, registerSingleton or registerLazySingleton And retrieve the desired object using get or call your locator das as function as its a callable class
Constructors
- GetIt.asNewInstance()
-
You should prefer to use the
instance()
method to access an instance of GetIt. If you really, REALLY need more than one GetIt instance please set allowMultipleInstances to true to signal you know what you are doing :-).factory
Properties
- allowReassignment ↔ bool
-
By default it's not allowed to register a type a second time.
If you really need to you can disable the asserts by settingallowReassignment= true
read / write
-
ready
→ Stream<
void> -
read-only
-
readyFuture
→ Future<
void> -
read-only
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Methods
-
call<
T> ([String instanceName ]) → T -
get<
T> ([String instanceName ]) → T -
retrieves or creates an instance of a registered type
T
depending on the registration function used for this type or based on a name. -
registerFactory<
T> (FactoryFunc< T> func, { String instanceName }) → void -
registers a type so that a new instance will be created on each call of get on that type
T
type to registerfunc
factory function for this typeinstanceName
if you provide a value here your factory gets registered with that name instead of a type. This should only be necessary if you need to register more than one instance of one type. Its highly not recommended -
registerLazySingleton<
T> (FactoryFunc< T> func, { String instanceName, bool signalsReady: false }) → void -
registers a type as Singleton by passing a factory function that will be called on the first call of get on that type
T
type to registerfunc
factory function for this type IfsignalsReady
is set totrue
it means that theready
property cannot emit a ready event until this registration was signalled readyinstanceName
if you provide a value here your factory gets registered with that name instead of a type. This should only be necessary if you need to register more than one instance of one type. Its highly not recommended -
registerSingleton<
T> (T instance, { String instanceName, bool signalsReady: false }) → void -
registers a type as Singleton by passing an
instance
of that type that will be returned on each call of get on that typeT
type to register IfsignalsReady
is set totrue
it means that theready
property cannot emit a ready event until this registration was signalled readyinstanceName
if you provide a value here your instance gets registered with that name instead of a type. This should only be necessary if you need to register more than one instance of one type. Its highly not recommended -
reset(
) → void - Clears all registered types. Handy when writing unit tests
-
signalReady(
[Object instance ]) → void -
unregister<
T> ({Object instance, String instanceName, void disposingFunction(T) }) → void -
Unregister an instance of an object or a factory/singleton by Type
T
or by nameinstanceName
if you need to dispose any resources you can do it usingdisposingFunction
function that provides a instance of your class to be disposed -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
toString(
) → String -
Returns a string representation of this object.
inherited
Operators
-
operator ==(
dynamic other) → bool -
The equality operator. [...]
inherited
Static Properties
- allowMultipleInstances ↔ bool
-
By default it's not allowed to create more than one GetIt instance.
If you really need to you can disable the asserts by settingallowReassignment= true
read / write
- I → GetIt
-
read-only
- instance → GetIt
-
read-only