Class: binding = new Binding()

Properties
Name Type Description
isLocked boolean
key string
scope BindingScope
tags Set
valueConstructor Constructor
PROPERTY_SEPARATOR string

constructor(key: string, isLocked: boolean) : Binding

Arguments
Name Type Description
key string
isLocked boolean

getValue(ctx: Context) : BoundValue | Promise <BoundValue>

This is an internal function optimized for performance. Users should use @inject(key) or ctx.get(key) instead.

Get the value bound to this key. Depending on isSync, this function returns either:

  • the bound value
  • a promise of the bound value

Consumers wishing to consume sync values directly should use isPromise to check the type of the returned value to decide how to handle it.

const result = binding.getValue(ctx);
if (isPromise(result)) {
  result.then(doSomething)
} else {
  doSomething(result);
}

Arguments
Name Type Description
ctx Context

inScope(scope: BindingScope) : void

Arguments
Name Type Description
scope BindingScope

lock() : this

tag(tagName: undefined) : this

Arguments
Name Type Description
tagName

to(value: BoundValue) : this

Bind the key to a constant value.

Arguments
Name Type Description
value BoundValue

The bound value.

toClass(ctor: Constructor) : this

Bind the key to an instance of the given class.

Arguments
Name Type Description
ctor Constructor

The class constructor to call. Any constructor arguments must be annotated with @inject so that we can resolve them from the context.

toDynamicValue(factoryFn: () => BoundValue | Promise <BoundValue> ) : this

Bind the key to a computed (dynamic) value.

Arguments
Name Type Description
factoryFn Function

The factory function creating the value. Both sync and async functions are supported.

toProvider(providerClass: Constructor) : this

Bind the key to a value computed by a Provider.

  • @example

export class DateProvider implements Provider<Date> {
  constructor(@inject('stringDate') private param: String){}
  value(): Date {
    return new Date(param);
  }
}

Arguments
Name Type Description
providerClass Constructor

unlock() : this

parseKeyWithPath(keyWithPath: string) :

Parse a string containing both the binding key and the path to the deeply nested property to retrieve.

Arguments
Name Type Description
keyWithPath string

The key with an optional path, e.g. "application.instance" or "config#rest.port".

validateKey(key: string) : string

Validate the binding key format. Please note that # is reserved.

Arguments
Name Type Description
key string

Binding key, such as `a, a.b, a:b, a/b

BoundValue = any

Class: context = new Context()

constructor(_parent: Context) : Context

Arguments
Name Type Description
_parent Context

bind(key: string) : Binding

Arguments
Name Type Description
key string

contains(key: string) : boolean

Arguments
Name Type Description
key string

find(pattern: string) :

Arguments
Name Type Description
pattern string

findByTag(pattern: string) :

Arguments
Name Type Description
pattern string

get(key: string) : Promise

Get the value bound to the given key, optionally return a (deep) property of the bound value.

Returns:

A promise of the bound value.

Arguments
Name Type Description
key string

getBinding(key: string) : Binding

Arguments
Name Type Description
key string

getSync(key: string) : BoundValue

Get the synchronous value bound to the given key, optionally return a (deep) property of the bound value.

This method throws an error if the bound value requires async computation (returns a promise). You should never rely on sync bindings in production code.

Returns:

A promise of the bound value.

Arguments
Name Type Description
key string

getValueOrPromise(keyWithPath: string) : ValueOrPromise

Get the value bound to the given key.

This is an internal version that preserves the dual sync/async result of Binding#getValue(). Users should use get() or getSync() instead.

Returns:

The bound value or a promise of the bound value, depending on how the binding was configured.

Arguments
Name Type Description
keyWithPath string

The binding key, optionally suffixed with a path to the (deeply) nested property to retrieve.

Interface: Injection

Descriptor for an injection point

Properties
Name Type Description
bindingKey string

Descriptor for an injection point

metadata Function

Descriptor for an injection point

resolve ResolverFunction

Descriptor for an injection point

Interface: ResolverFunction

A function to provide resolution of injected values

Getter(): Promise<T>

The function injected by @inject.getter(key).

Setter(value: T): void

The function injected by @inject.setter(key).

Arguments
Name Type Description
value T

describeInjectedArguments(target: any, method: undefined) :

Return an array of injection objects for parameters

Arguments
Name Type Description
target any

The target class for constructor or static methods, or the prototype for instance methods

method

describeInjectedProperties(target: any) :

Return a map of injection objects for properties

Arguments
Name Type Description
target any

The target class for static properties or prototype for instance properties.

isPromise(value: undefined) : boolean

Check whether a value is a Promise-like instance. Recognizes both native promises and third-party promise libraries.

Arguments
Name Type Description
value

The value to check.

Interface: Provider

Providers allow developers to compute injected values dynamically, with any dependencies required by the value getter injected automatically from the Context.

value() : ValueOrPromise

Returns:

The value to inject to dependents. This method can return a promise too, in which case the IoC framework will resolve this promise to obtain the value to inject.

Class: namespacedreflect = new NamespacedReflect()

constructor(namespace: string) : NamespacedReflect

Arguments
Name Type Description
namespace string

: namespace to bind this reflect context

decorate(decorators: undefined, target: Object, targetKey: undefined, descriptor: PropertyDescriptor) : PropertyDescriptor | Function

Arguments
Name Type Description
decorators
target Object
targetKey
descriptor PropertyDescriptor

defineMetadata(metadataKey: string, metadataValue: any, target: Object, propertyKey: undefined) : void

define metadata for a target class or it's property/method

Arguments
Name Type Description
metadataKey string
metadataValue any
target Object
propertyKey

deleteMetadata(metadataKey: string, target: Object, propertyKey: undefined) : boolean

Arguments
Name Type Description
metadataKey string
target Object
propertyKey

getMetadata(metadataKey: string, target: Object, propertyKey: undefined) : any

lookup metadata from a target object and its prototype chain

Arguments
Name Type Description
metadataKey string
target Object
propertyKey

getMetadataKeys(target: Object, propertyKey: undefined) :

Arguments
Name Type Description
target Object
propertyKey

getOwnMetadata(metadataKey: string, target: Object, propertyKey: undefined) : any

get own metadata for a target object or it's property/method

Arguments
Name Type Description
metadataKey string
target Object
propertyKey

getOwnMetadataKeys(target: Object, propertyKey: undefined) :

Arguments
Name Type Description
target Object
propertyKey

hasMetadata(metadataKey: string, target: Object, propertyKey: undefined) : boolean

Check if the target has corresponding metadata

Arguments
Name Type Description
metadataKey string

Key

target Object

Target

propertyKey

Optional property key

hasOwnMetadata(metadataKey: string, target: Object, propertyKey: undefined) : boolean

Arguments
Name Type Description
metadataKey string
target Object
propertyKey

metadata(metadataKey: string, metadataValue: any) :

Arguments
Name Type Description
metadataKey string
metadataValue any

KV(p: string): BoundValue

Arguments
Name Type Description
p string

instantiateClass(ctor: Constructor, ctx: Context) : T | Promise <T>

Create an instance of a class which constructor has arguments decorated with @inject.

The function returns a class when all dependencies were resolved synchronously, or a Promise otherwise.

Arguments
Name Type Description
ctor Constructor

The class constructor to call.

ctx Context

The context containing values for @inject resolution

resolveInjectedArguments(fn: Function, ctx: Context) : undefined | Promise <undefined>

Given a function with arguments decorated with @inject, return the list of arguments resolved using the values bound in ctx.

The function returns an argument array when all dependencies were resolved synchronously, or a Promise otherwise.

Arguments
Name Type Description
fn Function

The function for which the arguments should be resolved.

ctx Context

The context containing values for @inject resolution

resolveInjectedProperties(fn: Function, ctx: Context) : KV | Promise <KV>

Arguments
Name Type Description
fn Function
ctx Context