Skip to main content

Dependency Management

Locators is a Service Locator to register and retrieve you dependencies without BuildContext or any thing you only need the Type for the object you want and maybe need a tag

/// register
Locators.put(AuthService());

/// retrieve it
AuthService service = Locators.find<AuthService>();

The methods and it's configurable parameters are:

retrieve dependencies​

find​

return object from any register methods

AuthService service = Locators.find<AuthService>();

register dependencies​

put​

create the object now and register it

Locators.put<FooClass>(FooClass());
use tag if you need to put or find 2 objects of the same type

putLazy (lazyLoad dependencies)​

register a factory to create the object once when it first time needed

 Locators.putLazy<FooClass>((){
// this method will not be called until you need a object from `FooClass` and it will be called once
return FooClass();
});

This is all options you can set when using lazyPut:

factory​

register a factory to create NEW object every time it is needed

 Locators.factory<FooClass>((){
// this method will not be called until you need a object from `FooClass`
// and it will be called Every time you call Locators.find<FooClass>()
return FooClass();
});

delete​

To remove an instance/factory from Locators:

Locators.delete<FooClass>();