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
Sometimes services need a special method to initialize themselves. In the case of session stores, this method could be use to establish a connection to the database (redis, TypeORM, etc) instead of using lazy loading.
Constructors are not appropriate in this case because:
They do not support async operations.
Sub-dependencies are not accessible inside the constructor.
Unit testing is made harder.
Solution
Allow to add a boot method (sync or async) in each service. These methods will be executed (if they exist) after all the services have been instantiated and before AppController.init gets called (if init exists). No assumption can be made in which order the boot methods are called.
Issue
Sometimes services need a special method to initialize themselves. In the case of session stores, this method could be use to establish a connection to the database (redis, TypeORM, etc) instead of using lazy loading.
Constructors are not appropriate in this case because:
Solution
Allow to add a
boot
method (sync or async) in each service. These methods will be executed (if they exist) after all the services have been instantiated and beforeAppController.init
gets called (ifinit
exists). No assumption can be made in which order theboot
methods are called.Notes on implementation
createApp
to allow optionally passing ServiceManager object #599)ServiceManager.getAndBootOnce
for special cases.ServiceManager
, services must initialized only once.Related issues
#627 #598 #516 #538
The text was updated successfully, but these errors were encountered: