Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Injector

Dependencies provider implementation class

author

Jānis Radiņš / Kristaps Peļņa

Hierarchy

Index

Constructors

constructor

Properties

parent

parent: Injector

Parent injector of which to extract mappings that are not present in current injector.

returns

Accessors

destroyed

  • get destroyed(): boolean

listenerCount

  • get listenerCount(): number

Methods

addEventListener

  • Add event listener.

    Parameters

    • event: string

      Event name for which to listen to

    • listener: EventListener

      Listener function that will be invoked as event with specified name is dispatched.

    • Optional scope: Object

      Listener scope which will be applied as listener is invoked. (You can leave it undefined, if you don't care about scope that much).

    Returns EventMapping

    Null in case if event name is already mapped to same function. Or EventMapping object which is to be used in order to set some of mapping properties like once() which will make listener to be executed upon first event dispatch and then be gone.

createSubInjector

destroy

  • destroy(): void | Error
  • Destroy injector and all of its direct mappings.

    throws

    Error in case if Injector is already destroyed

    Returns void | Error

destroyInstance

  • destroyInstance(target: any): void | Error
  • Check if some instance has pre destroy methods defined and if so - invoke them

    throws

    Error in case if method is invoked on destroyed instance

    Parameters

    • target: any

      instance of injected values client

    Returns void | Error

Private dispatchEvent

  • dispatchEvent(event: Event): boolean
  • dispatchEvent(eventType: string, eventData?: any): boolean

Protected dispatchEventImpl

  • dispatchEventImpl(event: Event): boolean

get

  • get(type: Type<any>): any
  • Get injected instance mapped by required type. Invoking this method will return existing mapping or create new one in case if there have been no requests for this mapping or it's not mapped with instantiate call.

    throws

    Error in case if method i invoked on destroyed instance

    throws

    Error when no mapping was found for the specified dependency

    Parameters

    Returns any

getMapping

  • Returns the mapping for the specified dependency class Note that getMapping will only return mappings in exactly this injector, not ones mapped in an ancestor injector. To get mappings from ancestor injectors, query them using parent. This restriction is in place to prevent accidental changing of mappings in ancestor injectors where only the child's response is meant to be altered.

    throws

    Error in case if method i invoked on destroyed instance

    throws

    Error when no mapping was found for the specified dependency

    Parameters

    • type: Type<any>

      The type of the dependency to return the mapping for

    Returns InjectionMapping

    The mapping for the specified dependency class

hasDirectMapping

  • hasDirectMapping(type: Type<any>): boolean
  • Does this injector have a direct mapping for the given type?

    throws

    Error in case if method i invoked on destroyed instance

    Parameters

    • type: Type<any>

      The type

    Returns boolean

    True if the mapping exists

hasEventListener

  • hasEventListener(event: string, listener?: EventListener, scope?: Object): boolean

hasMapping

  • hasMapping(type: Type<any>): boolean
  • Does this injector (or any parents) have a mapping for the given type?

    throws

    Error in case if method i invoked on destroyed instance

    Parameters

    • type: Type<any>

      The type

    Returns boolean

    True if the mapping exists

injectInto

  • injectInto(target: any): any
  • Inspect given type and fill in type properties, clients for Injected values and invoke methods described with

    postconstruct

    if there are any.

    throws

    Error in case if method i invoked on destroyed instance

    throws

    Error in case if some Injector mapping could not be found.

    Parameters

    • target: any

      The instance to inject into

    Returns any

    Instance passed in via param with properties filled by injections and post construct methods invoked, or as it where in case if there is no metadata tpo apply.

instantiateInstance

  • instantiateInstance(type: Type<any>): any
  • Create instance of given type with constructor argument values injected, if any are described by metadata, and injected properties filled with values from Injector, if there are any. Invoking this method will also invoke any methods marked with @PostConstruct just as injected properties will be filled in.

    throws

    Error in case if method i invoked on destroyed instance

    throws

    Error in case if some Injector mapping could not be found.

    Parameters

    • type: Type<any>

      Instance type to be created.

    Returns any

    Newly created class instance of type described by input argument.

listenOnce

  • Add event listener that will be executed only once.

    Parameters

    • event: string

      Event name for which to listen to

    • listener: EventListener

      Listener function that will be invoked as event with specified name is dispatched.

    • Optional scope: Object

      Listener scope which will be applied as listener is invoked. (You can leave it undefined, if you don't care about scope that much).

    Returns EventMapping

    Null in case if event name is already mapped to same function. Or EventMapping object which is to be used in order to set some of mapping properties like once() which will make listener to be executed upon first event dispatch and then be gone.

map

  • Map type to injector.

    throws

    Error in case if method is invoked on destroyed instance

    throws

    Error in case if attempt to override sealed mapping is encountered

    Parameters

    • type: Type<any>

      The class type describing the mapping

    Returns InjectionMapping

removeAllEventListeners

  • removeAllEventListeners(scope?: Object): boolean
  • Remove all listeners registered with specified scope or with the whole dispatcher instance.

    Parameters

    • Optional scope: Object

      Scope from which all listeners mapped listeners will be removed. If not specified, all listeners will be removed from whole dispatcher instance.

    Returns boolean

    True if any listeners to remove where found; false otherwise.

removeEventListener

  • removeEventListener(event: string, listener: EventListener, scope?: Object): boolean

removeEventListeners

  • removeEventListeners(eventType: string, scope?: Object): boolean
  • Remove all listeners of a particular event from all scopes or the specified scope.

    Parameters

    • eventType: string

      Event name to be unmapped from all listeners.

    • Optional scope: Object

      Listener scope from which all listeners mapped to eventType will be removed.

    Returns boolean

    True if any of mappings have been found; false otherwise.

unMap

  • unMap(type: Type<any>): void
  • Removes the mapping described by the given type from current injector.

    throws

    Error in case if method i invoked on destroyed instance

    throws

    Error if unknown mapping is attempted to be unmapped

    throws

    Error if sealed mapping is attempted to be unmapped

    Parameters

    • type: Type<any>

      The class type describing the mapping

    Returns void