Skip to main content
Version: 2.x

singleton() function

@microsoft/fast-element/di.js > singleton

singleton() function

Registers the target class as a singleton dependency; the class will only be created once. Each consecutive time the dependency is resolved, the same instance will be returned.

Signature:

export declare function singleton<T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T>;

Parameters

Parameter

Type

Description

target

T & Partial<RegisterSelf<T>>

The class / constructor function to register as a singleton.

Returns:

T & RegisterSelf<T>

Example

@singleton()
class Foo &#123; &#125;