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.
Signature:
export declare class Application extends Context implements LifeCycleObserver
Extends: Context
Implements: LifeCycleObserver
Constructors
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 |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
options | readonly |
ApplicationConfig | |
state | readonly |
string | <p>Get the state of the application. The initial state is created and it can transition as follows by start and stop :</p><p>1. start - !started -> starting -> started - started -> started (no-op) 2. stop - (started | initialized) -> stopping -> stopped - ! (started || initialized) -> stopped (no-op)</p><p>Two types of states are expected: - stable, such as started and stopped - in process, such as booting and starting </p><p>Operations 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 .</p> |
Methods
Method | Modifiers | Description |
---|---|---|
assertInStates(op, states) | protected |
Assert current state of the application to be one of the expected values |
assertNotInProcess(op) | protected |
Assert there is no other operation is in progress, i.e., the state is not *ing , such as starting or stopping . |
awaitState(state) | protected |
|
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. | |
init() | <p>Initialize the application, and all of its registered observers. The application state is checked to ensure the integrity of initialize .</p><p>If the application is already initialized, no operation is performed.</p><p>This method is automatically invoked by start() if the application is not initialized.</p> |
|
interceptor(interceptor, nameOrOptions) | Register an interceptor | |
lifeCycleObserver(ctor, nameOrOptions) | Register a life cycle observer class | |
onInit(fn) | <p>Register a function to be called when the application initializes.</p><p>This is a shortcut for adding a binding for a LifeCycleObserver implementing a init() method.</p> |
|
onStart(fn) | <p>Register a function to be called when the application starts.</p><p>This is a shortcut for adding a binding for a LifeCycleObserver implementing a start() method.</p> |
|
onStop(fn) | <p>Register a function to be called when the application starts.</p><p>This is a shortcut for adding a binding for a LifeCycleObserver implementing a start() method.</p> |
|
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) | protected |
Transition the application to a new state and emit an event |
setupShutdown() | protected |
Set up signals that are captured to shutdown the application |
start() | <p>Start the application, and all of its registered observers. The application state is checked to ensure the integrity of start .</p><p>If the application is not initialized, it calls first init() to initialize the application. This only happens if start() is called for the first time.</p><p>If the application is already started, no operation is performed.</p> |
|
stop() | <p>Stop the application instance and all of its registered observers. The application state is checked to ensure the integrity of stop .</p><p>If the application is already stopped or not started, no operation is performed.</p> |