class ScopeManager
Since 0.1.0

Manages singleton and scoped instance caches for a container.

Constructors

ScopeManager(
singletons?: Map<string, unknown>,
scoped?: Map<string, unknown>
)
Parameters
optional
singletons: Map<string, unknown>

Map shared with the parent (or a fresh map for root)

optional
scoped: Map<string, unknown>

Per-scope map (always fresh)

Methods

Creates a child scope that shares singletons but has its own scoped map.

getScoped(token: string): unknown

Retrieves a cached scoped instance.

getSingleton(token: string): unknown

Retrieves a cached singleton instance.

hasScoped(token: string): boolean

Reports whether a scoped instance is cached.

hasSingleton(token: string): boolean

Reports whether a singleton is cached.

setScoped(
token: string,
instance: unknown
): void

Stores a scoped instance (local to this scope).

setSingleton(
token: string,
instance: unknown
): void

Stores a singleton instance (shared across all scopes).

Usage

import { ScopeManager } from "di-plugin/src/index.ts";