Page Contents

Home > @loopback/context > Context > (constructor)

Context.(constructor)

Create a new context.

Signature:

constructor(_parent?: Context | string, name?: string);

Parameters

Parameter Type Description
_parent Context | string The optional parent context
name string Name of the context, if not provided, a uuid will be generated as the name

Example

// Create a new root context, let the framework to create a unique name
const rootCtx = new Context();

// Create a new child context inheriting bindings from `rootCtx`
const childCtx = new Context(rootCtx);

// Create another root context called "application"
const appCtx = new Context('application');

// Create a new child context called "request" and inheriting bindings
// from `appCtx`
const reqCtx = new Context(appCtx, 'request');