Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ScopedContainer

A container that uses some parent container as a base, but can have other factories distinct from that parent.

If an instance is not found in this container, it will be resolved from the parent container.

However, if an instance IS found in this container, it will ALWAYS be resolved from this container, rather than the parent.

This can be used to create scope-specific containers that can still resolve the global dependencies, while keeping scope-specific dependencies separate.

example

The Request class from @extollo/lib is a ScopedContainer. It can resolve all dependencies that exist in the global Container, but it can also have request-specific services (like the Session) injected into it.

Hierarchy

Index

Constructors

constructor

Properties

Protected factories

factories: Collection<AbstractFactory<unknown>> = ...

Collection of factories registered with this container.

Protected instances

instances: Collection<InstanceRef> = ...

Collection of singleton instances produced by this container.

Private resolveParentScope

resolveParentScope: boolean = true

Protected staticOverrides

staticOverrides: Collection<{ base: StaticInstantiable<any>; override: StaticInstantiable<any> }> = ...

Collection of static-class overrides registered with this container.

Protected waitingResolveCallbacks

waitingResolveCallbacks: Collection<{ callback: (t: unknown) => unknown; key: any }> = ...

Collection of callbacks waiting for a dependency key to be resolved.

Methods

cloneTo

getDependencies

getExistingInstance

  • getExistingInstance(key: any): any

getStaticOverride

hasInstance

  • hasInstance(key: any): boolean

hasKey

  • hasKey(key: any): boolean

hasStaticOverride

make

  • make<T>(target: any, ...parameters: any[]): T
  • Create an instance of the given target. The target can either be a DependencyKey registered with this container (in which case, the singleton value will be returned), or an instantiable class.

    If the instantiable class has the Injectable decorator, its injectable parameters will be automatically injected into the instance.

    Type parameters

    • T

    Parameters

    • target: any
    • Rest ...parameters: any[]

    Returns T

makeByStaticOverride

onResolve

  • onResolve<T>(key: any): Promise<T>
  • Get a Promise that resolves the first time the given dependency key is resolved by the application. If it has already been resolved, the Promise will resolve immediately.

    Type parameters

    • T

    Parameters

    • key: any

    Returns Promise<T>

Protected produceFactory

purge

register

registerFactory

registerNamed

registerProducer

registerSingleton

registerSingletonInstance

  • registerSingletonInstance<T>(staticClass: any, instance: T): ScopedContainer

registerStaticOverride

release

resolve

resolveAndCreate

  • resolveAndCreate(key: any, ...parameters: any[]): any
  • Resolve the dependency key. If a singleton value for that key already exists in this container, return that value. Otherwise, use the factory an given parameters to produce and return the value.

    Parameters

    • key: any
    • Rest ...parameters: any[]

    Returns any

withoutParentScopes

  • withoutParentScopes<T>(closure: () => T): T
  • Execute a closure on this container, disabling parent-resolution. Effectively, the closure will have access to this container as if it were NOT a scoped container, and only contained its factories.

    Type parameters

    • T

    Parameters

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

    Returns T

Static fromParent

Static getContainer

Static realizeContainer

  • realizeContainer<T>(container: T): T
Extollo Logo

extollo (v. latin) - to lift up, to elevate

Extollo is a free & libre application framework in TypeScript.