@@ -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 ) {
0 commit comments