import { Binding , BoundValue , Constructor , createBindingFromClass , Provider , } from '@loopback/context' ; import { Application , ControllerClass , ServiceOrProviderClass , } from './application' ; import { LifeCycleObserver } from './lifecycle' ; import { Server } from './server' ; /**
 * A map of provider classes to be bound to a context
 */ export interface ProviderMap { [ key ] : Constructor < Provider < BoundValue > > ; } /**
 * A map of classes to be bound to a context
 */ export interface ClassMap { [ key ] : Constructor < BoundValue > ; } /**
 * A component declares a set of artifacts so that they can be contributed to
 * an application as a group
 */ export interface Component { /**
     * An array of controller classes
     */ controllers ? : ControllerClass [ ] ; example providers ? : ProviderMap ; example classes ? : ClassMap ; /**
     * A map of name/class pairs for servers
     */ servers ? : { [ name ] : Constructor < Server > ; } ; lifeCycleObservers ? : Constructor < LifeCycleObserver > [ ] ; /**
     * An array of service or provider classes
     */ services ? : ServiceOrProviderClass [ ] ; example bindings ? : Binding [ ] ; /**
     * Other properties
     */ [ prop ] : any ; } param app param component export function mountComponent ( app , component ) { if ( component . classes ) { for ( const classKey in component . classes ) { const binding = createBindingFromClass ( component . classes [ classKey ] , { key : classKey , } ) ; app . add ( binding ) ; } } if ( component . providers ) { for ( const providerKey in component . providers ) { const binding = createBindingFromClass ( component . providers [ providerKey ] , { key : providerKey , } ) ; app . add ( binding ) ; } } if ( component . bindings ) { for ( const binding of component . bindings ) { app . add ( binding ) ; } } if ( component . controllers ) { for ( const controllerCtor of component . controllers ) { app . controller ( controllerCtor ) ; } } if ( component . servers ) { for ( const serverKey in component . servers ) { app . server ( component . servers [ serverKey ] , serverKey ) ; } } if ( component . lifeCycleObservers ) { for ( const observer of component . lifeCycleObservers ) { app . lifeCycleObserver ( observer ) ; } } if ( component . services ) { for ( const service of component . services ) { app . service ( service ) ; } } }