← All packages

@searsuite/sear-foundation-di

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

enumScope

Enumerates Scope values.

enum memberPrototype: 1
enum memberSingleton: 0
classContainer

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.

constructorContainer(): Container
propertyreadonly types: Map<any, any>

Registered dependency tokens owned by this container.

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

Adds the dependency.

methodcreateLazy<T>(identifier: string): (): T

Creates the lazy.

methoddestroy(): void
methoddispose(): void
methodgetDependency(): void

Returns the dependency.

methodgetDependencyGraphText(): void

Returns the dependency graph text.

methodhasBinding(identifier: string | symbol): boolean

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

methodhasSingleton(identifier: string | symbol): boolean

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

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

Registers the value.

methodregisterBorrowedInstance<T>(identifier: Identifier<T>, instance: T): void

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

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

Registers the factory.

methodregisterInstance<T>(identifier: Identifier<T>, instance: T): void

Registers the instance.

methodregisterTypes(module: symbol, types: { }): void

Registers the types.

methodreset(): void

Releases created resources and removes every registration from this container.

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

Resolves a dependency from this container and its parent scope.

variableINJECT_METADATA_KEY
INJECT_METADATA_KEY: typeof INJECT_METADATA_KEY

Metadata key storing constructor parameter injection tokens.

variableINJECTABLE_METADATA_KEY
INJECTABLE_METADATA_KEY: typeof INJECTABLE_METADATA_KEY

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

functionInject
Inject(identifier: unknown): ParameterDecorator

Records the DI token that should satisfy one constructor parameter.

ReturnsParameter decorator used on constructor arguments.

identifier

Token registered in the DI container.

functionInjectable
Injectable(): ClassDecorator

Marks a class as injectable by the DI container.

ReturnsClass decorator that records injectable metadata.

functionSingleton
Singleton(): ClassDecorator

Marks a class as injectable and singleton-scoped.

ReturnsClass decorator that records singleton and injectable metadata.