Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support service initialization (boot method) #628

Closed
LoicPoullain opened this issue Feb 9, 2020 · 1 comment
Closed

Support service initialization (boot method) #628

LoicPoullain opened this issue Feb 9, 2020 · 1 comment

Comments

@LoicPoullain
Copy link
Member

LoicPoullain commented Feb 9, 2020

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:

  • 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.

Notes on implementation

Related issues

#627 #598 #516 #538

@LoicPoullain LoicPoullain added this to Backlog in Issue tracking via automation Feb 9, 2020
@LoicPoullain LoicPoullain moved this from Backlog to To Do in Issue tracking Feb 9, 2020
This was referenced Mar 2, 2020
This was referenced Apr 16, 2020
@LoicPoullain LoicPoullain moved this from To Do to Work In Progress in Issue tracking Apr 23, 2020
@LoicPoullain
Copy link
Member Author

Released with v1.8

Issue tracking automation moved this from Work In Progress to Done / Closed This Release May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Issue tracking
  
Done / Closed This Release
Development

No branches or pull requests

1 participant