The magic string Registration type.
The registered class constructor type.
Public constructor. The constructor of this class accepts the same
parameters as its overridden super
Map constructor and acts
the same. I.e., through instantiating this Singleton class and
passing a list of tuples
of Registrations and their corresponding
class constructors, these tuples may be preemptively registered.
Preemptively provide a class constructor by magic string:
import { type Registration, Registry } from '@sgrud/core';
import { Service } from './service';
const registration = 'sgrud.example.Service';
new Registry<Registration, typeof Service>([
[registration, Service]
]);
Private
Readonly
cachedInternal Mapping of all cached, i.e., forward-referenced, class constructors. Whenever a constructor, which is not currently registered, is requested as a Provider, an intermediary class is created and stored within this map until the actual constructor is registered. As soon as this happens, the intermediary class is removed from this map and further steps are taken to guarantee the transparent addressing of the actual constructor through the dropped intermediary class.
Private
Readonly
cachesInternally used WeakSet containing all intermediary classes created upon requesting a currently not registered constructor as provider. This set is used internally to check if a intermediary class has already been replaced by the actual constructor.
Overridden get method. Looks up the Provided constructor by magic string. If no provided constructor is found, an intermediary class is created, cached internally and returned. While this intermediary class and the functionality supporting it take care of inheritance, i.e., allow forward-referenced base classes to be extended, it cannot substitute for the actual extended constructor. Therefore, the static extension of forward-referenced classes is possible, but as long as the actual extended constructor is not registered (and therefore the intermediary class still caches the inheritance chain), the extending classes cannot be instantiated, called etc. Doing so will result in a ReferenceError being thrown.
The magic string to get the class constructor by.
The Provided constructor or a cached intermediary.
A ReferenceError when a cached class is invoked.
Retrieve a provided constructor by magic string:
import { type Registration, Registry } from '@sgrud/core';
import { type Service } from 'example-module';
const registration = 'sgrud.example.Service';
new Registry<Registration, typeof Service>().get(registration);
Overridden set method. Whenever a class constructor is provided by magic string through calling this method, a test is run, whether this constructor was previously requested and therefore cached as intermediary class. If so, the intermediary class is removed from the internal mapping and further steps are taken to guarantee the transparent addressing of the newly provided constructor through the previously cached and now dropped intermediary class.
This Registry instance.
Preemptively provide a constructor by magic string:
import { type Registration, Registry } from '@sgrud/core';
import { Service } from './service';
const registration = 'sgrud.example.Service';
new Registry<Registration, typeof Service>().set(registration, Service);
Generated using TypeDoc
The Singleton Registry is a mapping used by the Provider to lookup Provided constructors by Registrations upon class extension. Magic strings should represent sane module paths in dot-notation. Whenever a currently not registered constructor is requested, an intermediary class is created, cached internally and returned. When the actual constructor is registered later, the previously created intermediary class is removed from the internal caching and further steps are taken to guarantee the transparent addressing of the actual constructor through the dropped intermediary class.
Decorator
Singleton
See