Class: Singleton<V>
Class: Singleton<V>
Class representing a Singleton.
The Singleton class extends the ResolverBinding class, ensuring that the value is only resolved once. Subsequent calls to the resolve
method will return the previously resolved value, making it behave as a singleton.
Author
Mr. Stone evensstone@gmail.com
Extends
Type Parameters
V
V
extends BindingValue
The type of value that this binding holds.
Constructors
Constructor
new Singleton<V>(resolver): Singleton<V>;
Create a new instance of ResolverBinding.
Parameters
resolver
Resolver
<V
>
The resolver function to provide the binding value.
Returns
Singleton
<V
>
Throws
ContainerError if the resolver is not a function.
Inherited from
Properties
resolver
protected readonly resolver: Resolver<V>;
The resolver function used to provide the binding value.
This function will be called when the value is needed, allowing for lazy instantiation and dependency resolution. It should return an instance of type V
.
Inherited from
value?
protected optional value: V;
The value held by the binding.
This value is resolved at runtime, either directly or through a resolver function.
Inherited from
Methods
isResolved()
protected isResolved(): boolean;
Check if the value has been resolved.
Returns
boolean
A boolean indicating whether the value has been resolved.
Inherited from
resolve()
resolve(container): undefined | V;
Resolve and return the value of the binding.
If the value has already been resolved, return the cached value. Otherwise, use the resolver function to resolve the value, store it, and return it.
Parameters
container
The container to resolve dependencies from.
Returns
undefined
| V
The resolved value of the binding.
Throws
ContainerError if the value cannot be resolved.