You are viewing documentation for a previous version of FAST. The latest version is 3.x. View latest docs →

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

singleton() function

Registers the decorated 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>(): typeof singletonDecorator;

Returns:

typeof singletonDecorator

Example

@singleton()
class Foo { }