import { IContext , IExtension , IInjector , ILogger } from "@robotlegsjs/core" ; import { ContainerRegistry } from "./impl/ContainerRegistry" ; import { ManualStageObserver } from "./impl/ManualStageObserver" ; let installCount = 0 ; /**
 * This extension install a manual Stage Observer
 */ export class ManualStageObserverExtension implements IExtension { private static _manualStageObserver : ManualStageObserver ; private _injector : IInjector ; private _logger : ILogger ; inheritDoc public extend ( context ) { context . whenInitializing ( this . whenInitializing . bind ( this ) ) ; context . whenDestroying ( this . whenDestroying . bind ( this ) ) ; installCount ++ ; this . _injector = context . injector ; this . _logger = context . getLogger ( this ) ; } private whenInitializing ( ) { if ( ! ManualStageObserverExtension . _manualStageObserver ) { let containerRegistry = this . _injector . get < ContainerRegistry > ( ContainerRegistry ) ; this . _logger . debug ( "Creating genuine ManualStageObserver Singleton" ) ; ManualStageObserverExtension . _manualStageObserver = new ManualStageObserver ( containerRegistry ) ; } } private whenDestroying ( ) { installCount -- ; if ( installCount === 0 ) { this . _logger . debug ( "Destroying genuine ManualStageObserver Singleton" ) ; ManualStageObserverExtension . _manualStageObserver . destroy ( ) ; ManualStageObserverExtension . _manualStageObserver = null ; } } }