UNPKG

@loopback/docs

Version:
50 lines (32 loc) 1.35 kB
--- lang: en title: 'API docs: context.context.(constructor)' keywords: LoopBack 4.0, LoopBack 4 sidebar: lb4_sidebar permalink: /doc/en/lb4/apidocs.context.context.(constructor).html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/context](./context.md) &gt; [Context](./context.context.md) &gt; [(constructor)](./context.context.(constructor).md) ## Context.(constructor) Create a new context. <b>Signature:</b> ```typescript constructor(_parent?: Context | string, name?: string); ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | | \_parent | <code>Context &#124; string</code> | The optional parent context | | name | <code>string</code> | Name of the context, if not provided, a <code>uuid</code> will be generated as the name | ## Example ```ts // 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'); ```