Options
All
  • Public
  • Public/Protected
  • All
Menu

Injectable container class.

Type parameters

  • TContext

    type of the context which cane be used for scoping.

Hierarchy

  • Chevron

Index

Constructors

constructor

  • Creates a new, empty container.

    Returns Chevron

Methods

getInjectableInstance

  • getInjectableInstance<TInstance>(name: Nameable, context?: TContext | null): TInstance
  • Retrieves an instantiated injectable, recursively instantiating dependencies if they were not instantiated before.

    throws

    TypeError when no name can be determined for the provided nameable.

    throws

    Error when the injectable or a dependency cannot be found.

    throws

    Error when recursive dependencies are detected.

    Type parameters

    • TInstance

      type a constructed instance will have.

    Parameters

    • name: Nameable

      Either a raw string name or a nameable value that should be retrieved. See {@link #registerInjectable} for details.

    • Default value context: TContext | null = null

      Context to be used for instance checks. See Scope for details.

    Returns TInstance

    instantiated injectable for the given name.

hasInjectable

  • hasInjectable(name: Nameable): boolean
  • Checks if an injectable with the name provided is registered for this container, regardless if its instantiated or not. To check if an injectable is registered and instantiated, see {@link #hasInjectableInstance}.

    throws

    TypeError when no name can be determined for the provided nameable.

    Parameters

    • name: Nameable

      Either a raw string name or a nameable value that should be checked for. See {@link #registerInjectable} for details.

    Returns boolean

    if an injectable with the name provided is registered on this container.

hasInjectableInstance

  • hasInjectableInstance(name: Nameable, context?: TContext | null): boolean
  • Checks if an injectable with the name provided is registered and instantiated for this container. To check if an injectable is registered without checking for instantiation, see {@link #hasInjectable}.

    throws

    TypeError when no name can be determined for the provided nameable.

    Parameters

    • name: Nameable

      Either a raw string name or a nameable value that should be checked for. See {@link #registerInjectable} for details.

    • Default value context: TContext | null = null

      Context to be used for instance checks. See Scope for details.

    Returns boolean

    if an injectable with the name provided is registered and instantiated on this container.

registerInjectable

  • registerInjectable<TInstance, UInitializer, VDependency>(initializer: UInitializer, options?: InjectableOptions<TInstance, UInitializer, VDependency, TContext | null>): void
  • Registers a new injectable on this container.

    throws

    Error when an injectable with the requested name is already registered.

    throws

    TypeError when no name can be determined for this injectable or any of its dependencies.

    Type parameters

    • TInstance

      type a constructed instance will have.

    • UInitializer

      type of the provided initializer.

    • VDependency

      should not be set explicitly usually. Type of the dependencies used by this injectable.

    Parameters

    • initializer: UInitializer

      Initial value of this injectable. This can be any value, but usually a class or a different kind of function. During retrieval, the initial value might be transformed by the factory (see Factory for details). If no name is provided in the options (see description of the options parameter, section "name"), a name will be determined from the initializer through {@link getName}. or a value which is nameable. For details on nameable values see {@link getName}.

    • Default value options: InjectableOptions<TInstance, UInitializer, VDependency, TContext | null> = {}

      Options for this injectable. The following options exist:

      • name: Name for this injectable. If this is not provided, the name will be determined based on the initializer. (see description of the initializer parameter)
      • factory: Instantiation strategy to use when instantiating this injectable (see Factory for details). By default, DefaultFactory.IDENTITY is used. If your injectable is a class or factory function, consider using DefaultFactory.CLASS or DefaultFactory.FUNCTION instead respectively, or provide your own.
      • scope: Scoping strategy to use when retrieving instances (see Scope for details). By default, DefaultScope.SINGLETON is used. For different use cases, see DefaultScope.PROTOTYPE or provide your own.

    Returns void

Legend

  • Constructor
  • Property
  • Constructor
  • Method

Generated using TypeDoc