← All packages

API reference

@searsuite/sear-foundation-di

Editor-scoped dependency injection with explicit ownership and borrowed instances.

7 exportsderived from source

enumScopesource ↗
enum Scope

Enumerates Scope values.

enum memberPrototype
Prototype: 1
enum memberSingleton
Singleton: 0
classContainersource ↗
class Container

Dependency container.

Composition roots create and own explicit instances. Stateful runtimes must never share a process-wide container because resetting or rebinding one runtime would otherwise affect every other live runtime.

constructorconstructor
Container(): Container
propertytypes
readonly types: Map<any, any>

Registered dependency tokens owned by this container.

methodaddDependency
addDependency(parent: symbol, dependency: string | symbol): void

Adds the dependency.

parent: symbol
dependency: string | symbol
methodcreateLazy
createLazy<T>(identifier: string): (): T

Creates the lazy.

identifier: string
methoddestroy
destroy(): void
methoddispose
dispose(): void
methodgetDependency
getDependency(): void

Returns the dependency.

methodgetDependencyGraphText
getDependencyGraphText(): void

Returns the dependency graph text.

methodhasBinding
hasBinding(identifier: string | symbol): boolean

Returns whether this container has an explicit local binding for an identifier.

identifier: string | symbol
methodhasSingleton
hasSingleton(identifier: string | symbol): boolean

Returns whether a singleton has already been materialized for an identifier.

identifier: string | symbol
methodregister
register<T>(identifier: Identifier<T>, clazz: Constructor<T>, scope?: Scope): void

Registers the value.

identifier: Identifier<T>
clazz: Constructor<T>
scope: Scope
methodregisterBorrowedInstance
registerBorrowedInstance<T>(identifier: Identifier<T>, instance: T): void

Binds a parent-owned instance without acquiring its teardown responsibility.

identifier: Identifier<T>
instance: T
methodregisterFactory
registerFactory<T>(identifier: Identifier<T>, factory: FactoryFunction<T>, scope?: Scope): void

Registers the factory.

identifier: Identifier<T>
factory: FactoryFunction<T>
scope: Scope
methodregisterInstance
registerInstance<T>(identifier: Identifier<T>, instance: T): void

Registers the instance.

identifier: Identifier<T>
instance: T
methodregisterTypes
registerTypes(module: symbol, types: { }): void

Registers the types.

module: symbol
types: { }
methodreset
reset(): void

Releases created resources and removes every registration from this container.

methodresolve
resolve<T>(identifier: string | symbol): T

Resolves a dependency from this container and its parent scope.

identifier: string | symbol
variableINJECT_METADATA_KEYsource ↗
INJECT_METADATA_KEY: typeof INJECT_METADATA_KEY

Metadata key storing constructor parameter injection tokens.

variableINJECTABLE_METADATA_KEYsource ↗
INJECTABLE_METADATA_KEY: typeof INJECTABLE_METADATA_KEY

Metadata key that marks a class as resolvable by the DI container.

functionInjectsource ↗
Inject(identifier: unknown): ParameterDecorator

Records the DI token that should satisfy one constructor parameter.

ReturnsParameter decorator used on constructor arguments.

identifier: unknown

Token registered in the DI container.

functionInjectablesource ↗
Injectable(): ClassDecorator

Marks a class as injectable by the DI container.

ReturnsClass decorator that records injectable metadata.

functionSingletonsource ↗
Singleton(): ClassDecorator

Marks a class as injectable and singleton-scoped.

ReturnsClass decorator that records singleton and injectable metadata.