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

Module initialization using lifecycle hooks (ManagedModule) #44

Merged
merged 2 commits into from
Feb 23, 2022

Conversation

kon14
Copy link
Contributor

@kon14 kon14 commented Feb 23, 2022

This PR introduces module initialization with lifecycle hooks using ManagedModule and ModuleManager.

Modules deriving from ManagedModule can optionally implement the following lifecycle hooks to customize their behavior.

  • async onServerStart()
  • async preRegister()
  • async onRegister()
  • async preConfig(config: any)
  • async onConfig()

A ConduitService can be specified on the 'service' member.
Configurable modules can define a config schema using the optional abstract 'config' member.

Check out Authentication for an example implementation.
It's currently the only one migrated to the new format. I'll update the rest of the modules as a followup PR.

Writing modules based directly on ConduitServiceModule is still supported, but requires a minor single line change in module constructors (see Breaking Change below).

Closes #40.

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

ConduitServiceModule does not receive a ConduitGrpcSdk arg anymore.
Constructors of modules extending ConduitServiceModule directly should explicitly set 'this.grpcSdk' instead of passing it as an arg to base constructor.

The PR fulfills these requirements:

  • It's submitted to the master branch
  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx, where "xxx" is the issue number)

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

refactor(authentication): migrate to ManagedModule init
fix(chat,cms,database,email,forms,push-notifications,sms,storage): minor compat fix for ConduitServiceModule init

BREAKING CHANGE:
ConduitServiceModule does not receive a ConduitGrpcSdk arg anymore.
Constructors of modules extending ConduitServiceModule directly should explicitly set this.grpcSdk instead of passing it as an arg to base constructor.
libraries/grpc-sdk/src/interfaces/ConduitService.ts Outdated Show resolved Hide resolved
libraries/grpc-sdk/src/classes/ConfigController.ts Outdated Show resolved Hide resolved
libraries/grpc-sdk/src/classes/ManagedModule.ts Outdated Show resolved Hide resolved
modules/authentication/src/Authentication.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] Module initialization using lifecycle hooks
2 participants