The Targeted constructor type.
The Targeted InstanceType.
Overridden get method. Calling this method looks up the linked instance
based on the supplied target
constructor. If no linked instance is found,
one is created by calling the new
operator on the target
constructor.
Therefor the target
constructors must not require parameters.
The target
constructor for which to retrieve an instance.
The already linked or a newly constructed and linked instance.
Retrieve a linked instance:
import { Linker } from '@sgrud/core';
import { Service } from './service';
new Linker<typeof Service>().get(Service);
The getAll method returns all linked instances, which satisfy
instanceof target
. Use this method when multiple linked target
constructors extend the same base class and are to be retrieved.
The target
constructor for which to retrieve instances.
All already linked instance of the target
constructor.
Retrieve all linked instances of a Service
:
import { Linker } from '@sgrud/core';
import { Service } from './service';
new Linker<typeof Service>().getAll(Service);
Generated using TypeDoc
The Singleton Linker class provides the means to lookup and retrieve instances of Targeted constructors. The Linker is used throughout the SGRUD client libraries, e.g., by the Factor decorator, to provide and retrieve different centrally provisioned class instances.
Decorator
Singleton
Example
Preemptively link an instance: