Class: application = new Application()

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

Properties
Name Type Default Value Flags Description
options ApplicationConfig public exported constructorProperty

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

constructor(options: ApplicationConfig) : Application

Parameters
Name Type Default Value Flags Description
options ApplicationConfig {}

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

component(componentCtor: Constructor<Component>, name: undefined | string) : Binding<Component>

Add a component to this application and register extensions such as controllers, providers, and servers from the component.

Parameters
Name Type Default Value Flags Description
componentCtor Constructor<Component>

The component class to add.

name undefined | string optional

Optional component name, default to the class name


export class ProductComponent {
  controllers = [ProductController];
  repositories = [ProductRepo, UserRepo];
  providers = {
    [AUTHENTICATION_STRATEGY]: AuthStrategy,
    [AUTHORIZATION_ROLE]: Role,
  };
};

app.component(ProductComponent);

controller(controllerCtor: ControllerClass, name: undefined | string) : Binding

Register a controller class with this application.

Returns:

The newly created binding, you can use the reference to further modify the binding, e.g. lock the value to prevent further modifications.

class MyController {
}
app.controller(MyController).lock();

Parameters
Name Type Default Value Flags Description
controllerCtor ControllerClass

The controller class (constructor function).

name undefined | string optional

Optional controller name, default to the class name

getServer(target: Constructor<T> | string) : Promise<T>

Retrieve the singleton instance for a bound constructor.

Parameters
Name Type Default Value Flags Description
target Constructor<T> | string

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

lifeCycleObserver(ctor: Constructor<T>, name: undefined | string) : Binding<T>

Register a life cycle observer class

Parameters
Name Type Default Value Flags Description
ctor Constructor<T>

A class implements LifeCycleObserver

name undefined | string optional

Optional name for the life cycle observer

server(ctor: Constructor<T>, name: undefined | string) : Binding<T>

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.

app.server(RestServer);
// This server constructor will be bound under "servers.RestServer".
app.server(RestServer, "v1API");
// This server instance will be bound under "servers.v1API".

Returns:

Binding for the server class

Parameters
Name Type Default Value Flags Description
ctor Constructor<T>

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

name undefined | string optional

Optional override for key name.

servers(ctors: Constructor<T>[]) : Binding[]

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.

If you wish to control the binding keys for particular server instances, use the app.server function instead.

app.servers([
 RestServer,
 GRPCServer,
]);
// Creates a binding for "servers.RestServer" and a binding for
// "servers.GRPCServer";

Returns:

An array of bindings for the registered server classes

Parameters
Name Type Default Value Flags Description
ctors Constructor<T>[]

An array of Server constructors.

setMetadata(metadata: ApplicationMetadata) : void

Set application metadata. @loopback/boot calls this method to populate the metadata from package.json.

Parameters
Name Type Default Value Flags Description
metadata ApplicationMetadata

Application metadata

start() : Promise<void>

Start the application, and all of its registered observers.

stop() : Promise<void>

Stop the application instance and all of its registered observers.

Interface: ApplicationConfig

Configuration for application

Interface: ApplicationMetadata

Type description for package.json

Properties
Name Type Default Value Flags Description
description string exported

Type description for package.json

name string exported

Type description for package.json

version string exported

Type description for package.json

Interface: JSONArray

Properties
Name Type Default Value Flags Description
Array ArrayConstructor exported

Interface: JSONObject

Type alias: ControllerClass = Constructor

Interface: ClassMap

A map of classes to be bound to a context

Interface: Component

A component declares a set of artifacts so that they cane be contributed to an application as a group

Properties
Name Type Default Value Flags Description
bindings Binding[] exported optional

An array of bindings to be aded to the application context. For example,

const bindingX = Binding.bind('x').to('Value X');
this.bindings = [bindingX]

classes ClassMap exported optional

A map of classes to be bound to the application context.

For example:

{
  'rest.body-parsers.xml': XmlBodyParser
}

controllers ControllerClass[] exported optional

An array of controller classes

lifeCycleObservers Constructor<LifeCycleObserver>[] exported optional

A component declares a set of artifacts so that they cane be contributed to an application as a group

providers ProviderMap exported optional

A map of providers to be bound to the application context

  • For example:
    {
    'authentication.strategies.ldap': LdapStrategyProvider
    }

servers undefined | anonymous exported optional

A map of name/class pairs for servers

Interface: ProviderMap

A map of provider classes to be bound to a context

Function: mountComponent

mountComponent(app: Application, component: Component) : void

Mount a component to an Application.

Parameters
Name Type Default Value Flags Description
app Application

component Component

Namespace: CoreBindings

Namespace for core binding keys

const CoreBindings.APPLICATION_CONFIG = BindingKey.create( 'application.config', )

Binding key for application configuration

const CoreBindings.APPLICATION_INSTANCE = BindingKey.create( 'application.instance', )

Binding key for application instance itself

const CoreBindings.APPLICATION_METADATA = BindingKey.create( 'application.metadata', )

Binding key for the content of package.json

const CoreBindings.COMPONENTS = "components"

Binding key for components

const CoreBindings.CONTROLLERS = "controllers"

Namespace for core binding keys

const CoreBindings.CONTROLLER_CLASS = BindingKey.create( 'controller.current.ctor', )

Binding key for the controller class resolved in the current request context

const CoreBindings.CONTROLLER_CURRENT = BindingKey.create('controller.current')

Binding key for the controller instance resolved in the current request context

const CoreBindings.CONTROLLER_METHOD_META = "controller.method.meta"

Binding key for the controller method metadata resolved in the current request context

const CoreBindings.CONTROLLER_METHOD_NAME = BindingKey.create( 'controller.current.operation', )

Binding key for the controller method resolved in the current request context

const CoreBindings.LIFE_CYCLE_OBSERVERS = "lifeCycleObservers"

Namespace for core binding keys

const CoreBindings.LIFE_CYCLE_OBSERVER_OPTIONS = BindingKey.create< LifeCycleObserverOptions >('lifeCycleObserver.options')

Binding key for life cycle observer options

const CoreBindings.LIFE_CYCLE_OBSERVER_REGISTRY = BindingKey.create< LifeCycleObserverRegistry >('lifeCycleObserver.registry')

Binding key for life cycle observer options

const CoreBindings.SERVERS = "servers"

Binding key for servers

Namespace: CoreTags

const CoreTags.COMPONENT = "component"

Binding tag for components

const CoreTags.CONTROLLER = "controller"

Binding tag for controllers

const CoreTags.LIFE_CYCLE_OBSERVER = "lifeCycleObserver"

Binding tag for life cycle observers

const CoreTags.LIFE_CYCLE_OBSERVER_GROUP = "lifeCycleObserverGroup"

Binding tag for group name of life cycle observers

const CoreTags.SERVER = "server"

Binding tag for servers

Interface: LifeCycleObserver

Observers to handle life cycle start/stop events

start() : ValueOrPromise<void>

The method to be invoked during start

stop() : ValueOrPromise<void>

The method to be invoked during stop

Function: asLifeCycleObserver

asLifeCycleObserver(binding: Binding<T>) : Binding<T>

A BindingTemplate function to configure the binding as life cycle observer by tagging it with CoreTags.LIFE_CYCLE_OBSERVER.

Parameters
Name Type Default Value Flags Description
binding Binding<T>

Binding object

Function: isLifeCycleObserver

isLifeCycleObserver(obj) : boolean

Test if an object implements LifeCycleObserver

Parameters
Name Type Default Value Flags Description
obj anonymous

An object

Function: isLifeCycleObserverClass

isLifeCycleObserverClass(ctor: Constructor<unknown>) : boolean

Test if a class implements LifeCycleObserver

Parameters
Name Type Default Value Flags Description
ctor Constructor<unknown>

A class

Function: lifeCycleObserver

lifeCycleObserver(group: string, specs: BindingSpec[]) : anonymous

Sugar decorator to mark a class as life cycle observer

Parameters
Name Type Default Value Flags Description
group string ""

Optional observer group name

specs BindingSpec[] rest

Optional bindings specs

Function: lifeCycleObserverFilter

lifeCycleObserverFilter(binding: Binding<unknown>) : boolean

Find all life cycle observer bindings. By default, a binding tagged with CoreTags.LIFE_CYCLE_OBSERVER. It's used as BindingFilter.

Parameters
Name Type Default Value Flags Description
binding Binding<unknown>

Interface: Server

Defines the requirements to implement a Server for LoopBack applications: start() : Promise stop() : Promise It is recommended that each Server implementation creates its own child Context, which inherits from the parent Application context. This way, any Server-specific bindings will remain local to the Server instance, and will avoid polluting its parent module scope.

Properties
Name Type Default Value Flags Description
listening boolean exported

Tells whether the server is listening for connections or not