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

Add an init method in AppController to initialize the app #517

Closed
LoicPoullain opened this issue Aug 20, 2019 · 2 comments
Closed

Add an init method in AppController to initialize the app #517

LoicPoullain opened this issue Aug 20, 2019 · 2 comments

Comments

@LoicPoullain
Copy link
Member

Issue

In many situations, we need to make some initialization when starting the server (for example establishing a connection to another server).

For now, we can do it src/index.ts but it is not very handy to access the app services using DI.

const app = createApp(AppController);
app.foal.services.get(MyServiceA).doSomething();
app.foal.services.get(MyServiceB).doAnotherSomething();

Related issue

#516

@LoicPoullain
Copy link
Member Author

Possible Solution

Add an optional init method in the AppController that will be called after the services and controllers have been instantiated.

export class AppController {
  @dependency a: MyServiceA;
  @dependency b: MyServiceB;

  init() {
   this.a.doSomething();
   this.b.doAnotherThing();
  }
}

For backward compatibility on version 1 (people might have already a method named init here), the feature would be disabled by default and should be enabled using a configuration key in config/.

@LoicPoullain
Copy link
Member Author

Feature added in v1.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

1 participant