Interface Binder

Bind Ids to producers.

Hierarchy

Implemented by

Methods

bindAsyncFactory

  • Bind an InjectableId to an asynchronous factory that will be invoked on demand when the object is needed. The factory should produce the needed value (asynchronously of course). NOTE: The container will not invoke any @PostConstruct present on the class, this is the responsibility of the factory. WARNING!!! The factory may not throw and must return a valid Promise (which can be pending, resolved, rejected, etc.).

    Parameters

    Returns BindAs<T, AsyncFactory<T>>

bindClass

bindConstant

  • Bind an InjectableId to a constant value. Constants are by their very nature singleton, and are assumed to be error proof.

    Parameters

    Returns void

bindFactory

  • Bind an InjectableId to a synchronous factory that will be invoked on demand when the object is needed. The factory should produce the needed value NOTE: The container will not invoke any @PostConstruct present on the class, this is the responsibility of the factory.

    Parameters

    Returns BindAs<T, SyncFactory<T>>

get

  • Return an instance of <T> previously bound to 'id'.

    throws

    Error if the InjectableId was never registered, OR if there are unresolved asynchronous dependencies in the dependency tree for 'id'.

    Parameters

    Returns T

isIdKnown

  • Check to see if the existing InjectableId is known (aka has been bound). Error callbacks may wish to know if a particular InjectableId is available. Also the Binder's bindXXX calls always overwrite any previous bindings, so you may want to use this as a gate.

    Parameters

    Returns boolean

resolve

resolveSingletons

  • resolveSingletons(asyncOnly?: boolean, parentRecursion?: boolean): Promise<void>
  • This essentially pre creates/loads all singleton InjectableIds currently known to the Binder. This may be helpful if you wish to use Injector.get on a dependency tree that has asynchronous singletons within the tree.

    Parameters

    • Optional asyncOnly: boolean

      Only resolve AsyncFactorys as well as any bound classes that have an asynchronous @PostConstruct decorator. WARNING: If true, SyncFactorys will not be resolved even if they are Singletons.

    • Optional parentRecursion: boolean

      If true and the the container has a parent, resolveIfSingleton will first be called for the parent

    Returns Promise<void>

    A Promise that resolves when all Singleton's have been resolved, OR rejects if one or more of the Singleton's failed to resolve. NOTE: Rejection does not occur until all Singleton resolutions have settled, and the rejection reason/err will be a Map<InjectableId, Error>

Generated using TypeDoc