You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dimitar Zabaznoski edited this page Jun 16, 2021
·
3 revisions
To manage dependencies this project uses a service locator by a 3rd party library - get_it
Setup
The service locator is initialized in pre_app_config and has 2 configured scopes - Global and User scope.
Global 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.
User scope
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.
UserScopeHook
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
Usage
To use the service locator access the global variable serviceLocator.get<UserManager>().