Stone.js API
    Preparing search index...

    Class representing a Container.

    The Container class acts as a dependency injection container, managing bindings and resolving instances. It supports different types of bindings, such as singletons, factories, and instances, and allows the use of aliases for bindings. This makes it easier to manage and resolve complex dependency trees in an application.

    Mr. Stone evensstone@gmail.com

    Hierarchy (View Summary)

    Implements

    Index
    • Set a binding as alias.

      Adds one or more aliases for a given binding key.

      Parameters

      • key: BindingKey

        The binding value.

      • aliases: string | string[]

        One or more strings representing the aliases.

      Returns this

      The container instance.

    • AutoBind value to the service container.

      Type Parameters

      Parameters

      • name: BindingKey

        A key to make the binding. Can be anything.

      • Optionalitem: V

        The item to bind.

      • singleton: boolean = true

        Bind as singleton when true.

      • alias: string | string[] = []

        Key binding aliases.

      Returns this

      The container instance.

    • Bind a resolver function into the container under the provided key, returning a new instance each time.

      Type Parameters

      Parameters

      • key: BindingKey

        The key to associate with the value.

      • resolver: Resolver<V>

        The resolver function to provide the value.

      Returns this

      The container instance.

    • Bind a resolver function into the container under the provided key, returning a new instance each time if not already bound.

      Type Parameters

      Parameters

      • key: BindingKey

        The key to associate with the value.

      • resolver: Resolver<V>

        The resolver function to provide the value.

      Returns this

      The container instance.

    • Check if a value is already bound in the container by its key.

      Parameters

      Returns boolean

      True if the key is bound, false otherwise.

    • Reset the container so that all bindings are removed.

      Returns this

      The container instance.

    • Resolve a value from the container by its key and return it in a factory function.

      Type Parameters

      Parameters

      Returns () => V

      A factory function that returns the resolved value.

    • Retrieve the value of the aliases property.

      Returns Map<string, BindingKey>

      A map of all aliases registered in the container.

    • Check if a value is already bound in the container by its key.

      Parameters

      Returns boolean

      True if the key is bound, false otherwise.

    • Bind a single instance or value into the container under the provided key if not already bound.

      Parameters

      Returns this

      The container instance.

    • Check if an alias exists in the container.

      Parameters

      Returns boolean

      True if the alias exists, false otherwise.

    • Resolve a registered value from the container by its key.

      Type Parameters

      Parameters

      Returns V

      The resolved value.

      ContainerError if the key cannot be resolved.

    • Resolve a value from the container by its key, binding it if necessary.

      Type Parameters

      Parameters

      • key: BindingKey

        The key to resolve.

      • singleton: boolean = false

        Whether to bind as a singleton if not already bound.

      Returns V

      The resolved value.

    • Bind a resolver function into the container under the provided key as a singleton.

      The resolver function will be called once, and the resulting value will be cached for future use.

      Type Parameters

      Parameters

      • key: BindingKey

        The key to associate with the singleton value.

      • resolver: Resolver<V>

        The resolver function to provide the value.

      Returns this

      The container instance.

    • Bind a resolver function into the container under the provided key as a singleton if not already bound.

      Type Parameters

      Parameters

      • key: BindingKey

        The key to associate with the singleton value.

      • resolver: Resolver<V>

        The resolver function to provide the value.

      Returns this

      The container instance.