import { IContext , IExtension , IInjector } from "@robotlegsjs/core" ; import { IViewManager } from "../viewManager/api/IViewManager" ; import { ViewManager } from "../viewManager/impl/ViewManager" ; import { ContainerRegistry } from "./impl/ContainerRegistry" ; /**
 * This extension install a View Manager into the context
 */ export class ViewManagerExtension implements IExtension { private static _containerRegistry : ContainerRegistry ; private _injector : IInjector ; private _viewManager : IViewManager ; inheritDoc public extend ( context ) { context . whenInitializing ( this . whenInitializing . bind ( this ) ) ; context . whenDestroying ( this . whenDestroying . bind ( this ) ) ; this . _injector = context . injector ; ViewManagerExtension . _containerRegistry = ViewManagerExtension . _containerRegistry || new ContainerRegistry ( ) ; this . _injector . bind ( ContainerRegistry ) . toConstantValue ( ViewManagerExtension . _containerRegistry ) ; this . _injector . bind ( IViewManager ) . to ( ViewManager ) . inSingletonScope ( ) ; } private whenInitializing ( ) { this . _viewManager = this . _injector . get < IViewManager > ( IViewManager ) ; } private whenDestroying ( ) { this . _viewManager . removeAllHandlers ( ) ; this . _injector . unbind ( IViewManager ) ; this . _injector . unbind ( ContainerRegistry ) ; } }