Page Contents

Home > @loopback/core > Application

Application class

Application is the container for various types of artifacts, such as components, servers, controllers, repositories, datasources, connectors, and models.


export declare class Application extends Context implements LifeCycleObserver 

Extends: Context

Implements: LifeCycleObserver


Constructor Modifiers Description
(constructor)(parent)   Create an application with the given parent context
(constructor)(config, parent)   Create an application with the given configuration and parent context


Property Modifiers Type Description
options   ApplicationConfig  
state   string Get the state of the application. The initial state is created and it can transition as follows by start and stop:1. start - !started -> starting -> started - started -> started (no-op) 2. stop - started -> stopping -> stopped - !started -> stopped (no-op)Two types of states are expected: - stable, such as started and stopped - in process, such as booting and startingOperations such as start and stop can only be called at a stable state. The logic should immediately set the state to a new one indicating work in process, such as starting and stopping.


Method Modifiers Description
assertInStates(op, states)   Assert current state of the application to be one of the expected values
assertNotInProcess(op)   Assert there is no other operation is in progress, i.e., the state is not *ing, such as starting or stopping.
component(componentCtor, nameOrOptions)   Add a component to this application and register extensions such as controllers, providers, and servers from the component.
controller(controllerCtor, nameOrOptions)   Register a controller class with this application.
getServer(target)   Retrieve the singleton instance for a bound server.
interceptor(interceptor, nameOrOptions)   Register an interceptor
lifeCycleObserver(ctor, nameOrOptions)   Register a life cycle observer class
server(ctor, nameOrOptions)   Bind a Server constructor to the Application’s master context. Each server constructor added in this way must provide a unique prefix to prevent binding overlap.
servers(ctors)   Bind an array of Server constructors to the Application’s master context. Each server added in this way will automatically be named based on the class constructor name with the “servers.” prefix.
service(cls, nameOrOptions)   Add a service to this application.
setMetadata(metadata)   Set application metadata. @loopback/boot calls this method to populate the metadata from package.json.
setState(state)   Transition the application to a new state and emit an event
setupShutdown()   Set up signals that are captured to shutdown the application
start()   Start the application, and all of its registered observers. The application state is checked to ensure the integrity of start.If the application is already started, no operation is performed.
stop()   Stop the application instance and all of its registered observers. The application state is checked to ensure the integrity of stop.If the application is already stopped or not started, no operation is performed.