Dynasty is a simple Dependency Injection container. This is the primary class for creating and managing dependencies.

Constructors

Methods

  • Configuration.

    Type Parameters

    • const C extends UnknownRecord

      The type of the configuration. Usually supplied.

    Parameters

    • initial: Readonly<C>

      The initial configuration value.

    Returns Config<C>

    The configuration.

  • Create a dependency that is resolved every time it is used.

    Type Parameters

    • TArgs extends readonly unknown[]

      The argument types for the FactoryFn. Generally inferred.

    • const R

      The return type. Generally inferred.

    Parameters

    Returns Dependency<R>

    The dependency. Resolved on use.

  • A singleton. Create a dependency that is resolved once.

    Type Parameters

    • TArgs extends readonly unknown[]

      The argument types for the FactoryFn. Generally inferred.

    • const R

      The return type. Generally inferred.

    Parameters

    Returns Dependency<R>

    The dependency. Resolved on use.

  • Resolve a list of dependencies.

    Type Parameters

    • const R extends readonly unknown[]

      The return types of the dependencies. Generally inferred.

    Parameters

    • Rest...dependencies: Dependencies<R>

      A list of dependencies to resolve.

    Returns Promise<R>

    The values of the resolved dependencies.

  • Create a dependency that wraps a value.

    Type Parameters

    • const T

      The type of the value.

    Parameters

    • value: T

      The value to wrap.

    Returns Dependency<T>

    The dependency. Resolved on use.

  • Wrap a newable class/function in a factory function.

    Type Parameters

    • const TArgs extends readonly unknown[]

      The argument types for the FactoryClass. Generally inferred.

    • const R

      The return type. Generally inferred.

    Parameters

    Returns FactoryFn<TArgs, R>

    A callable factory function.