Stone.js API
    Preparing search index...

    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.

    Mr. Stone evensstone@gmail.com

    Type Parameters

    • V extends BindingValue

      The type of value that this binding holds.

    Hierarchy (View Summary)

    Index
    resolved: boolean

    Whether the value has been resolved at least once.

    Tracked explicitly (not inferred from value !== undefined) so a binding whose resolved value is legitimately undefined is still considered resolved — preserving the singleton guarantee and avoiding repeated resolver side effects.

    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.

    value?: V

    The value held by the binding.

    This value is resolved at runtime, either directly or through a resolver function.

    • Check if the value has been resolved.

      Returns boolean

      A boolean indicating whether the value has been resolved.

    • 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: IContainer

        The container to resolve dependencies from.

      Returns V

      The resolved value of the binding.

      ContainerError if the value cannot be resolved.