Documents injecute 1.x · Migrating from 0.x
Skip to content

Function: createTag() ​

createTag<N>(name): Tag<unknown, N>

Defined in: src/dependencies.ts:68

Creates a tag: a name for an extension point that modules contribute services to. Calling the tag builds the key of a contribution (route('orders') is 'orders:route'); a factory that depends on collect(tag) receives every contribution. Give the tag the contributions' type with .of<T>().

Tag names are non-empty and contain no : or ..

Type Parameters ​

N ​

N extends string

Parameters ​

name ​

N

Returns ​

Tag<unknown, N>

Throws ​

INJECUTE_INVALID_OPTION for an invalid name.

Example ​

ts
export const route = createTag('route').of<Route>();

// a module contributes
c.addSingleton(route('orders'), (db): Route => ordersRoute(db), ['db']);
// the owner collects
c.addSingleton('router', (routes) => new Router(routes), [collect(route)]);

Released under the MIT License.