Interface ContainerFull<T>

Container interface for full functionality.

interface ContainerFull<T> {
    addScoped: (<T>(factory: (() => T), ref?: RefSymbol<T>) => RefSymbol<T>);
    addSingleton: (<T>(factory: (() => T), ref?: RefSymbol<T>) => RefSymbol<T>);
    addTransient: (<T>(factory: (() => T), ref?: RefSymbol<T>) => RefSymbol<T>);
    clear: (<T>(ref?: RefSymbol<T>) => boolean);
    clone: (() => T);
    get: (<T>(ref: RefSymbol<T>) => undefined | T);
    getOrFail: (<T>(ref: RefSymbol<T>) => T);
    merge: ((...args: T[]) => void);
    remove: (<T>(ref?: RefSymbol<T>) => boolean);
    scopeCreate: (() => T);
    scopeRenew: (() => void);
    setScoped: (<T>(data: T, ref?: RefSymbol<T>) => RefSymbol<T>);
    setSingleton: (<T>(data: T, ref?: RefSymbol<T>) => RefSymbol<T>);
}

Type Parameters

Hierarchy (view full)

Implemented by

Properties

addScoped: (<T>(factory: (() => T), ref?: RefSymbol<T>) => RefSymbol<T>)

Add scoped factory and create matching ref. If ref is given it is reused

A scoped factory is only used once per scope.

Type declaration

    • <T>(factory, ref?): RefSymbol<T>
    • Type Parameters

      • T

      Parameters

      • factory: (() => T)
          • (): T
          • Returns T

      • Optionalref: RefSymbol<T>

        reference

      Returns RefSymbol<T>

      given or newly created reference

addSingleton: (<T>(factory: (() => T), ref?: RefSymbol<T>) => RefSymbol<T>)

Add singleton factory and create matching ref. If ref is given it is reused

A singleton factory is only used once and the result cached until it is cleared.

Type declaration

    • <T>(factory, ref?): RefSymbol<T>
    • Type Parameters

      • T

      Parameters

      • factory: (() => T)
          • (): T
          • Returns T

      • Optionalref: RefSymbol<T>

        reference

      Returns RefSymbol<T>

      given or newly created reference

addTransient: (<T>(factory: (() => T), ref?: RefSymbol<T>) => RefSymbol<T>)

Add transient factory and create matching ref. If ref is given it is reused

A transient factory is used for every access and the result is never cached.

Type declaration

    • <T>(factory, ref?): RefSymbol<T>
    • Type Parameters

      • T

      Parameters

      • factory: (() => T)
          • (): T
          • Returns T

      • Optionalref: RefSymbol<T>

        reference

      Returns RefSymbol<T>

      given or newly created reference

clear: (<T>(ref?: RefSymbol<T>) => boolean)

Remove all or specific ref from container but leaves factory intact. Only relevant for singleton or scoped services

Type declaration

    • <T>(ref?): boolean
    • Type Parameters

      • T

      Parameters

      Returns boolean

      true if something was removed

clone: (() => T)

Create a fully independent clone of the current container

Type declaration

    • (): T
    • Returns T

      container

get: (<T>(ref: RefSymbol<T>) => undefined | T)

Retrieves the data from the container referenced by the given RefSymbol. If there is no data available it returns undefined but never throws an exception.

Type declaration

    • <T>(ref): undefined | T
    • Type Parameters

      • T

      Parameters

      Returns undefined | T

      The referenced data from the container or undefined.

getOrFail: (<T>(ref: RefSymbol<T>) => T)

Retrieves the data from the container referenced by the given RefSymbol. If there is no data available it throws an exception defined by the container.

Type declaration

    • <T>(ref): T
    • Type Parameters

      • T

      Parameters

      Returns T

      The referenced data from the container.

merge: ((...args: T[]) => void)

Merge two or more containers. Conflicting factories, service lifetimes and singletons are overwritten by priority, see args.

Type declaration

    • (...args): void
    • Parameters

      • Rest...args: T[]

        container, ordered descending by priority

      Returns void

remove: (<T>(ref?: RefSymbol<T>) => boolean)

Removes all or specific ref from container which includes the factory.

Type declaration

    • <T>(ref?): boolean
    • Type Parameters

      • T

      Parameters

      Returns boolean

      true if something was removed

scopeCreate: (() => T)

Creates separate scope from the current container. Data except scope is shared between copy and original object.

Type declaration

    • (): T
    • Returns T

      container

scopeRenew: (() => void)

Renews scope of current container.

setScoped: (<T>(data: T, ref?: RefSymbol<T>) => RefSymbol<T>)

Add scoped data and create matching ref. If ref is given it is reused

The data is only available in the current scope.

Type declaration

setSingleton: (<T>(data: T, ref?: RefSymbol<T>) => RefSymbol<T>)

Add singleon data and create matching ref. If ref is given it is reused

The data is available everywhere.

Type declaration