@@ -112,18 +112,26 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
112
112
this . logger = LoggerFactory__default . getLogger ( '@alt-javascript/cdi/ApplicationContext' , this . config ) ;
113
113
}
114
114
115
- async start ( ) {
116
- await this . lifeCycle ( ) ;
115
+ async start ( options ) {
116
+ this . logger . verbose ( 'Application context starting.' ) ;
117
+ await this . lifeCycle ( options ) ;
118
+ this . logger . verbose ( 'Application context started.' ) ;
117
119
}
118
120
119
- async lifeCycle ( ) {
121
+ async lifeCycle ( options ) {
120
122
this . logger . verbose ( `ApplicationContext (${ this . name } ) lifecycle started.` ) ;
123
+ await this . prepare ( ) ;
124
+ return this . run ( options ) ;
125
+ }
126
+
127
+ async prepare ( ) {
128
+ this . logger . verbose ( `ApplicationContext (${ this . name } ) lifecycle prepare phase started.` ) ;
121
129
await this . parseContexts ( ) ;
122
130
this . createSingletons ( ) ;
123
131
this . injectSingletonDependencies ( ) ;
124
132
this . initialiseSingletons ( ) ;
125
133
this . registerSingletonDestroyers ( ) ;
126
- return this . run ( ) ;
134
+ this . logger . verbose ( `ApplicationContext ( ${ this . name } ) lifecycle prepare phase completed.` ) ;
127
135
}
128
136
129
137
detectConfigContext ( ) {
@@ -182,8 +190,10 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
182
190
for ( let i = 0 ; i < this . contexts . length ; i ++ ) {
183
191
if ( this . contexts [ i ] ) {
184
192
if ( this . contexts [ i ] ?. constructor ?. name === 'Context' ) {
193
+ // eslint-disable-next-line no-await-in-loop
185
194
await this . parseContextComponents ( this . contexts [ i ] ) ;
186
195
} else {
196
+ // eslint-disable-next-line no-await-in-loop
187
197
await this . parseContextComponents ( new Context ( this . contexts [ i ] ) ) ;
188
198
}
189
199
} else {
@@ -205,6 +215,7 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
205
215
const name = contextKeys [ i ] ;
206
216
const component = contextComponent [ name ] ;
207
217
component . name = name ;
218
+ // eslint-disable-next-line no-await-in-loop
208
219
await this . parseContextComponent ( component ) ;
209
220
}
210
221
}
@@ -215,6 +226,7 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
215
226
if ( context . components ) {
216
227
if ( Array . isArray ( context . components ) ) {
217
228
for ( let i = 0 ; i < context . components . length ; i ++ ) {
229
+ // eslint-disable-next-line no-await-in-loop
218
230
await this . deriveContextComponent ( context . components [ i ] ) ;
219
231
}
220
232
}
@@ -249,17 +261,16 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
249
261
$component . wireFactory = component . wireFactory ;
250
262
// TODO - dynamic import (async)
251
263
if ( component . require ) {
252
- try {
264
+ try {
253
265
// eslint-disable-next-line
254
266
let module = await import ( component . require ) ;
255
267
$component . Reference = module . default ;
256
268
$component . isClass = ( $component ?. Reference ?. prototype ?. constructor !== undefined ) ;
257
269
} catch ( err ) {
258
- this . logger . error ( err ) ;
270
+ this . logger . error ( err ) ;
259
271
}
260
272
}
261
273
262
-
263
274
$component . properties = component . properties || constructr ?. properties ;
264
275
$component . profiles = component . profiles || constructr ?. profiles ;
265
276
if ( ! $component . profiles ) {
@@ -474,19 +485,27 @@ var ApplicationContext = (function (_, LoggerFactory, ConfigFactory) {
474
485
this . logger . verbose ( 'Registering singleton destroyers completed' ) ;
475
486
}
476
487
477
- async run ( ) {
478
- const keys = Object . keys ( this . components ) ;
479
- for ( let i = 0 ; i < keys . length ; i ++ ) {
480
- const component = this . components [ keys [ i ] ] ;
481
- if ( component . scope === Scopes . SINGLETON ) {
482
- if ( typeof component . instance . run === 'function' ) {
483
- component . instance . run ( ) ;
484
- } else if ( typeof component . run === 'string' ) {
485
- component . instance [ component . run ] ( ) ;
488
+ async run ( options ) {
489
+ if ( ! ( options ) || options ?. run ) {
490
+ this . logger . verbose ( `ApplicationContext (${ this . name } ) lifecycle run phase started.` ) ;
491
+
492
+ const keys = Object . keys ( this . components ) ;
493
+ for ( let i = 0 ; i < keys . length ; i ++ ) {
494
+ const component = this . components [ keys [ i ] ] ;
495
+ if ( component . scope === Scopes . SINGLETON ) {
496
+ if ( typeof component . run === 'string' ) {
497
+ component . instance [ component . run ] ( ) ;
498
+ } else if ( typeof component . instance . run === 'function' ) {
499
+ component . instance . run ( ) ;
500
+ }
486
501
}
502
+
503
+ this . logger . verbose ( `ApplicationContext (${ this . name } ) lifecycle run phase completed.` ) ;
487
504
}
505
+ } else {
506
+ this . logger . verbose ( `ApplicationContext (${ this . name } ) skipping lifecycle run phase.` ) ;
488
507
}
489
- this . logger . verbose ( 'Application context started' ) ;
508
+ this . logger . verbose ( `ApplicationContext ( ${ this . name } ) lifecycle completed.` ) ;
490
509
}
491
510
492
511
get ( reference , defaultValue , targetArgs ) {
0 commit comments