Skip to content

Commit 4fa275b

Browse files
author
craig
committed
2.0.1 / 2022-03-28
================== * Separate lifeclye into prepare and run - @craigparra
1 parent f841d43 commit 4fa275b

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

ApplicationContext.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,26 @@ export default class ApplicationContext {
6565
this.logger = LoggerFactory.getLogger('@alt-javascript/cdi/ApplicationContext', this.config);
6666
}
6767

68-
async start() {
69-
await this.lifeCycle();
68+
async start(options) {
69+
this.logger.verbose('Application context starting.');
70+
await this.lifeCycle(options);
71+
this.logger.verbose('Application context started.');
7072
}
7173

72-
async lifeCycle() {
74+
async lifeCycle(options) {
7375
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle started.`);
76+
await this.prepare();
77+
return this.run(options);
78+
}
79+
80+
async prepare() {
81+
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle prepare phase started.`);
7482
await this.parseContexts();
7583
this.createSingletons();
7684
this.injectSingletonDependencies();
7785
this.initialiseSingletons();
7886
this.registerSingletonDestroyers();
79-
return this.run();
87+
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle prepare phase completed.`);
8088
}
8189

8290
detectConfigContext() {
@@ -430,19 +438,27 @@ export default class ApplicationContext {
430438
this.logger.verbose('Registering singleton destroyers completed');
431439
}
432440

433-
async run() {
434-
const keys = Object.keys(this.components);
435-
for (let i = 0; i < keys.length; i++) {
436-
const component = this.components[keys[i]];
437-
if (component.scope === Scopes.SINGLETON) {
438-
if (typeof component.instance.run === 'function') {
439-
component.instance.run();
440-
} else if (typeof component.run === 'string') {
441-
component.instance[component.run]();
441+
async run(options) {
442+
if (null || options || options?.run) {
443+
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle run phase started.`);
444+
445+
const keys = Object.keys(this.components);
446+
for (let i = 0; i < keys.length; i++) {
447+
const component = this.components[keys[i]];
448+
if (component.scope === Scopes.SINGLETON) {
449+
if (typeof component.run === 'string') {
450+
component.instance[component.run]();
451+
} else if (typeof component.instance.run === 'function') {
452+
component.instance.run();
453+
}
442454
}
455+
456+
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle run phase completed.`);
443457
}
458+
} else {
459+
this.logger.verbose(`ApplicationContext (${this.name}) skipping lifecycle run phase.`);
444460
}
445-
this.logger.verbose('Application context started');
461+
this.logger.verbose(`ApplicationContext (${this.name}) lifecycle completed.`);
446462
}
447463

448464
get(reference, defaultValue, targetArgs) {

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2.0.1 / 2022-03-28
2+
==================
3+
4+
* Separate lifeclye into prepare and run - @craigparra
5+
16
2.0.0 / 2022-03-11
27
==================
38

0 commit comments

Comments
 (0)