-
Notifications
You must be signed in to change notification settings - Fork 35
Service Locator
To manage dependencies this project uses a service locator by a 3rd party library - get_it
The service locator is initialized in pre_app_config
and has 2 configured scopes - Global and User scope.
The global scope manages dependencies that are available through the entire lifespan of the app.
Example: the UserManager, API service, platform communication, global data storage, etc.
You'll find the global dependencies at di/service_locator.dart
.
The user scope manages dependencies that are available as long as there is a logged-in user. They are created when the user is logged in and destroyed when is logged out.
Example: TasksRepository - Repository that holds tasks specific to a User that should not be globally available when the user is not logged in.
You'll find the user scope dependencies at di/user_scope.dart
.
Path: di/user_scope_hook.dart
The user scope hook is a UserEventHook
that listens for user lifecycle events and creates and destroys the user scope accordingly.
The user scope component lifecycle:
a. created on:
- app start if there is a logged-in user
- user login
b. destroyed on:
- user logout
c. recreated on:
- new user login after session expiry
d. kept intact on:
- same user login after session expiry
To use the service locator access the global variable serviceLocator.get<UserManager>()
.
For more detailed usage head to the get it documentation.