-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow components to contribute start actions #1845
Copy link
Copy link
Closed
Description
When bootstrap LB4 application I need to execute/load some actions on startup.
In the example above I need to register job task.
The CustomComponent is added to QueueJobApplication through QueueMixin.
The CustomComponent throw error becase don't have the repository bound to the context.
Is it possible to add QueueMixin after the RepositoryMixin are loaded all repositories to context?
Example:
export class CustomComponent implements Component {
constructor(
@repository(QueueRepository) private queueRepository: QueueRepository,
) {
this.registerProcess();
}
}
export function QueueMixin<T extends Class<any>>(superClass: T) {
return class extends superClass {
// A mixin class has to take in a type any[] argument!
// tslint:disable-next-line:no-any
constructor(...args: any[]) {
super(...args);
this.component(CustomComponent);
}
}
}
export class QueueJobApplication extends BootMixin(
QueueMixin(ServiceMixin(RepositoryMixin((RestApplication))),
) {
constructor(options: ApplicationConfig = {}) {
super(options);
// Set up the custom sequence
this.sequence(MySequence);
this.projectRoot = __dirname;
}
}LB3 Example (script added under server/boot):
module.export = app => {
const {QueueRepository} = app.models;
QueueRepository.once('dataSourceAdded', () => {
// Execute/load some logic
});
}Reactions are currently unavailable