Home Manual Reference Source Repository
import {Injector} from 'ug-layout/di/Injector'
public class | source

Injector

Direct Subclass:

RenderableInjector

A dependency injector for resolving dependencies. Injectors are hierarchicle.

Example:

const injector = new Injector([
  { provide: 'test', useValue: 'blorg' },
  { provide: 'factory', useFactory: () => 'BOOM' },
  { provide: 'myClass', useClass: MyClass },
  MyClass
]);

injector.get('test'); // => 'blorg';
injector.get('factory'); // => 'BOOM';
injector.get('myClass'); // => instanceof MyClass;
injector.get(MyClass); // => instanceof MyClass;

Static Method Summary

Static Public Methods
public static

fromInjectable(injectable: Type<any>, providers: ProviderArg[], parent: Injector): Injector

Creates a new injector from an annotated injectable Class.

public static

resolveInjectables(injectable: *): *[]

Constructor Summary

Public Constructor
public

constructor(providers: ProviderArg[], _parent: Injector | null)

Creates an instance of Injector.

Member Summary

Public Members
public get

The parent injector if it is set.

Method Summary

Public Methods
public

get(token: *, defaultValue: *, metadata: InjectionMetadata): *

Gets a dependecy from the provided token.

public

getDependencies(metadata: *): *

public

instantiate(Ref: *, d: ...*): *

public

invoke(fn: *, providers: *): *

public

Registers a provider with the injector.

public

Creates a new injector with the given providers and sets this injector as it's parent.

public

resolveAndInstantiate(provider: *): T

Resolves the given provider with this injector.

public

setParent(parent: Injector)

Programmatically set the parent injector.

Static Public Methods

public static fromInjectable(injectable: Type<any>, providers: ProviderArg[], parent: Injector): Injector source

Creates a new injector from an annotated injectable Class. See Injectable for more details.

Params:

NameTypeAttributeDescription
injectable Type<any>
providers ProviderArg[]
  • optional
  • default: []
parent Injector
  • optional

Return:

Injector

public static resolveInjectables(injectable: *): *[] source

Params:

NameTypeAttributeDescription
injectable *

Return:

*[]

Public Constructors

public constructor(providers: ProviderArg[], _parent: Injector | null) source

Creates an instance of Injector.

Params:

NameTypeAttributeDescription
providers ProviderArg[]
  • optional
  • default: []

List of providers for this injector.

_parent Injector | null
  • optional
  • default: null

A parent injector.

Public Members

public get parent: Injector | null source

The parent injector if it is set.

Public Methods

public get(token: *, defaultValue: *, metadata: InjectionMetadata): * source

Gets a dependecy from the provided token.

Params:

NameTypeAttributeDescription
token *
defaultValue *
  • optional
metadata InjectionMetadata
  • optional
  • default: {}

Return:

*

public getDependencies(metadata: *): * source

Params:

NameTypeAttributeDescription
metadata *

Return:

*

public instantiate(Ref: *, d: ...*): * source

Params:

NameTypeAttributeDescription
Ref *
d ...*

Return:

*

public invoke(fn: *, providers: *): * source

Params:

NameTypeAttributeDescription
fn *
providers *

Return:

*

public registerProvider(provider: ProviderArg) source

Registers a provider with the injector.

Params:

NameTypeAttributeDescription
provider ProviderArg

public resolveAndCreateChild(providers: ProviderArg[]): Injector source

Creates a new injector with the given providers and sets this injector as it's parent.

Params:

NameTypeAttributeDescription
providers ProviderArg[]
  • optional
  • default: []

Return:

Injector

public resolveAndInstantiate(provider: *): T source

Resolves the given provider with this injector.

Params:

NameTypeAttributeDescription
provider *

Return:

T

public setParent(parent: Injector) source

Programmatically set the parent injector.

Params:

NameTypeAttributeDescription
parent Injector