import { C as BoundInjectionToken, M as InjectionToken, N as InjectionTokenSchemaType, P as InjectionTokenType, T as ClassTypeWithArgument, d as InjectableScope, f as IContainer, g as Join, i as Factorable, j as FactoryInjectionToken, l as ServiceInitializationContext, n as Registry, s as Injectors, t as FactoryRecord, u as InjectableType, v as UnionToArray, w as ClassType, x as AnyInjectableType } from "./registry-DKbKWFvJ.cjs"; import { ZodType, z } from "zod/v4"; //#region src/internal/core/name-resolver.d.mts /** * Handles instance name generation with support for requestId and scope. * * Generates unique instance identifiers based on token, arguments, and scope. * Request-scoped services MUST include requestId in their name for proper isolation. */ declare class NameResolver { private readonly logger; private readonly instanceNameCache; constructor(logger?: Console | null); /** * Generates a unique instance name based on token, arguments, requestId, and scope. * * Name formats: * - Singleton/Transient without args: `${tokenId}` * - Singleton/Transient with args: `${tokenId}:${argsHash}` * - Request without args: `${tokenId}:requestId=${requestId}` * - Request with args: `${tokenId}:requestId=${requestId}:${argsHash}` * * @param token The injection token * @param args Optional arguments * @param requestId Optional request ID (required for request-scoped services) * @param scope Optional scope (used to determine if requestId should be included) * @returns The generated instance name */ generateInstanceName(token: InjectionTokenType, args?: any, requestId?: string, scope?: InjectableScope): string; /** * Upgrades an existing instance name to include requestId. * Preserves any args hash that might already be in the name. * * Examples: * - `TokenName` → `TokenName:requestId=req-123` * - `TokenName:abc123` → `TokenName:requestId=req-123:abc123` * * @param existingName The existing instance name (without requestId) * @param requestId The request ID to add * @returns The upgraded instance name with requestId */ upgradeInstanceNameToRequest(existingName: string, requestId: string): string; /** * Formats a single argument value for instance name generation. */ formatArgValue(value: any): string; } //#endregion //#region src/errors/di-error.d.mts declare enum DIErrorCode { FactoryNotFound = "FactoryNotFound", FactoryTokenNotResolved = "FactoryTokenNotResolved", InstanceNotFound = "InstanceNotFound", InstanceDestroying = "InstanceDestroying", CircularDependency = "CircularDependency", TokenValidationError = "TokenValidationError", TokenSchemaRequiredError = "TokenSchemaRequiredError", ClassNotInjectable = "ClassNotInjectable", ScopeMismatchError = "ScopeMismatchError", PriorityConflictError = "PriorityConflictError", StorageError = "StorageError", InitializationError = "InitializationError", DependencyResolutionError = "DependencyResolutionError", UnknownError = "UnknownError", } declare class DIError extends Error { readonly code: DIErrorCode; readonly message: string; readonly context?: Record; constructor(code: DIErrorCode, message: string, context?: Record); static factoryNotFound(name: string): DIError; static factoryTokenNotResolved(token: string | symbol | unknown): DIError; static instanceNotFound(name: string): DIError; static instanceDestroying(name: string): DIError; static unknown(message: string | Error, context?: Record): DIError; static circularDependency(cycle: string[]): DIError; static tokenValidationError(message: string, schema: InjectionTokenSchemaType | undefined, value: unknown): DIError; static tokenSchemaRequiredError(token: string | symbol | unknown): DIError; static classNotInjectable(className: string): DIError; static scopeMismatchError(token: string | symbol | unknown, expectedScope: string, actualScope: string): DIError; static priorityConflictError(token: string | symbol | unknown, records: FactoryRecord[]): DIError; static storageError(message: string, operation: string, instanceName?: string): DIError; static initializationError(serviceName: string, error: Error | string): DIError; static dependencyResolutionError(serviceName: string, dependencyName: string, error: Error | string): DIError; } //#endregion //#region src/internal/holder/instance-holder.d.mts /** * Represents the lifecycle status of an instance holder. */ declare enum InstanceStatus { /** Instance has been successfully created and is ready for use */ Created = "created", /** Instance is currently being created (async initialization in progress) */ Creating = "creating", /** Instance is being destroyed (cleanup in progress) */ Destroying = "destroying", /** Instance creation failed with an error */ Error = "error", } /** Callback function for instance destruction listeners */ type InstanceDestroyListener = () => void | Promise; /** * Instance holder in the Creating state. * The instance is null while creation is in progress. */ interface InstanceHolderCreating { status: InstanceStatus.Creating; name: string; instance: null; creationPromise: Promise<[undefined, Instance]> | null; destroyPromise: null; type: InjectableType; scope: InjectableScope; deps: Set; destroyListeners: InstanceDestroyListener[]; createdAt: number; /** Tracks which services this holder is currently waiting for (for circular dependency detection) */ waitingFor: Set; } /** * Instance holder in the Created state. * The instance is available and ready for use. */ interface InstanceHolderCreated { status: InstanceStatus.Created; name: string; instance: Instance; creationPromise: null; destroyPromise: null; type: InjectableType; scope: InjectableScope; deps: Set; destroyListeners: InstanceDestroyListener[]; createdAt: number; /** Tracks which services this holder is currently waiting for (for circular dependency detection) */ waitingFor: Set; } /** * Instance holder in the Destroying state. * The instance may still be available but is being cleaned up. */ interface InstanceHolderDestroying { status: InstanceStatus.Destroying; name: string; instance: Instance | null; creationPromise: null; destroyPromise: Promise; type: InjectableType; scope: InjectableScope; deps: Set; destroyListeners: InstanceDestroyListener[]; createdAt: number; /** Tracks which services this holder is currently waiting for (for circular dependency detection) */ waitingFor: Set; } /** * Instance holder in the Error state. * The instance field contains the error that occurred during creation. */ interface InstanceHolderError { status: InstanceStatus.Error; name: string; instance: Error; creationPromise: null; destroyPromise: null; type: InjectableType; scope: InjectableScope; deps: Set; destroyListeners: InstanceDestroyListener[]; createdAt: number; /** Tracks which services this holder is currently waiting for (for circular dependency detection) */ waitingFor: Set; } /** * Holds the state of a service instance throughout its lifecycle. * * Tracks creation/destruction promises, dependency relationships, * destroy listeners, and current status (Creating, Created, Destroying, Error). */ type InstanceHolder = InstanceHolderCreating | InstanceHolderCreated | InstanceHolderDestroying | InstanceHolderError; //#endregion //#region src/internal/holder/holder-storage.interface.d.mts /** * Result type for holder retrieval operations. * - [undefined, holder] - Holder found successfully * - [DIError, holder?] - Error occurred (holder may be available for waiting) * - null - No holder exists */ type HolderGetResult = [undefined, InstanceHolder] | [DIError, InstanceHolder?] | null; /** * Interface for abstracting holder storage operations. * * Enables unified instance resolution logic regardless of where * holders are stored. This is the key abstraction for the unified storage pattern. */ interface IHolderStorage { /** * The scope this storage handles. */ readonly scope: InjectableScope; /** * Retrieves an existing holder by instance name. * * @param instanceName The unique identifier for the instance * @returns * - [undefined, holder] if found and ready/creating * - [DIError, holder?] if found but in error/destroying state * - null if not found */ get(instanceName: string): HolderGetResult; /** * Stores a holder by instance name. * * @param instanceName The unique identifier for the instance * @param holder The holder to store */ set(instanceName: string, holder: InstanceHolder): void; /** * Deletes a holder by instance name. * * @param instanceName The unique identifier for the instance * @returns true if the holder was deleted, false if it didn't exist */ delete(instanceName: string): boolean; /** * Creates a new holder in "Creating" state with a deferred promise. * The holder is NOT automatically stored - call set() to store it. * * @param instanceName The unique identifier for the instance * @param type The injectable type * @param deps The set of dependency names * @returns A tuple containing the deferred promise resolver and the holder */ createHolder(instanceName: string, type: InjectableType, deps: Set): [ReturnType>, InstanceHolder]; /** * Checks if this storage should be used for the given scope. */ handles(scope: InjectableScope): boolean; /** * Gets all instance names in this storage. */ getAllNames(): string[]; /** * Iterates over all holders with a callback. * * @param callback Function called for each holder with (name, holder) */ forEach(callback: (name: string, holder: InstanceHolder) => void): void; /** * Finds a holder by its instance value (reverse lookup). * * @param instance The instance to search for * @returns The holder if found, null otherwise */ findByInstance(instance: unknown): InstanceHolder | null; /** * Finds all instance names that depend on the given instance name. * * @param instanceName The instance name to find dependents for * @returns Array of instance names that have this instance as a dependency */ findDependents(instanceName: string): string[]; /** * Updates dependency references when instance names change. * Used during scope upgrades when instance names are regenerated with requestId. * * @param oldName The old instance name * @param newName The new instance name */ updateDependencyReference(oldName: string, newName: string): void; } //#endregion //#region src/internal/lifecycle/lifecycle-event-bus.d.mts /** * Event bus for service lifecycle events (create, destroy, etc.). * * Enables loose coupling between services by allowing them to subscribe * to lifecycle events of their dependencies without direct references. * Used primarily for invalidation cascading. */ declare class LifecycleEventBus { private readonly logger; private listeners; constructor(logger?: Console | null); on(ns: string, event: Event, listener: (event: Event) => void): () => void; emit(key: string, event: string): Promise[] | undefined>; } //#endregion //#region src/internal/core/service-invalidator.d.mts interface ClearAllOptions { /** Whether to wait for all services to settle before starting (default: true) */ waitForSettlement?: boolean; } interface InvalidationOptions { /** Whether to emit events after invalidation (default: true) */ emitEvents?: boolean; /** Custom event emitter function */ onInvalidated?: (instanceName: string) => Promise; /** Whether to cascade invalidation to dependents (default: false - events handle it) */ cascade?: boolean; } /** * Manages graceful service cleanup with event-based invalidation. * * Uses event subscriptions instead of manual dependent finding. * When a service is created, it subscribes to destroy events of its dependencies. * When a dependency is destroyed, the event automatically invalidates dependents. */ declare class ServiceInvalidator { private readonly eventBus; private readonly logger; constructor(eventBus: LifecycleEventBus | null, logger?: Console | null); /** * Invalidates a service using a specific storage. * Event-based invalidation means dependents are automatically invalidated * via destroy event subscriptions - no need to manually find dependents. * * @param service The instance name to invalidate * @param storage The storage to use for this invalidation * @param options Additional options for invalidation behavior */ invalidateWithStorage(service: string, storage: IHolderStorage, options?: InvalidationOptions): Promise; /** * Sets up destroy event subscriptions for a service's dependencies. * Called when a service is successfully instantiated. * * @param serviceName The name of the service * @param dependencies The set of dependency names * @param storage The storage to use for invalidation * @param holder The holder for the service (to add unsubscribe to destroy listeners) */ setupDependencySubscriptions(serviceName: string, dependencies: Set, storage: IHolderStorage, holder: InstanceHolder): void; /** * Gracefully clears all services in a specific storage. * This allows clearing request-scoped services using a RequestStorage. */ clearAllWithStorage(storage: IHolderStorage, options?: ClearAllOptions): Promise; /** * Waits for all services in a specific storage to settle. */ readyWithStorage(storage: IHolderStorage): Promise; /** * Invalidates a single holder using a specific storage. */ private invalidateHolderWithStorage; /** * Common invalidation logic for holders based on their status. */ private invalidateHolderByStatus; /** * Destroys a holder using a specific storage. */ private destroyHolderWithStorage; /** * Waits for a holder to settle (either created, destroyed, or error state). */ private waitForHolderToSettle; /** * Emits events to listeners for instance lifecycle events. */ private emitInstanceEvent; } //#endregion //#region src/internal/core/token-resolver.d.mts /** * Handles token validation and resolution. * * Focuses on token validation, normalization, and argument validation. * Name generation is handled by NameResolver. */ declare class TokenResolver { private readonly logger; constructor(logger?: Console | null); /** * Normalizes a token to an InjectionToken. * Handles class constructors by getting their injectable token. * * @param token A class constructor, InjectionToken, BoundInjectionToken, or FactoryInjectionToken * @returns The normalized InjectionTokenType */ normalizeToken(token: AnyInjectableType): InjectionTokenType; /** * Gets the underlying "real" token from wrapped tokens. * For BoundInjectionToken and FactoryInjectionToken, returns the wrapped token. * For other tokens, returns the token itself. * * @param token The token to unwrap * @returns The underlying InjectionToken */ getRealToken(token: InjectionTokenType): InjectionToken; /** * Convenience method that normalizes a token and then gets the real token. * Useful for checking registry entries where you need the actual registered token. * * @param token Any injectable type * @returns The underlying InjectionToken */ getRegistryToken(token: AnyInjectableType): InjectionToken; /** * Validates and resolves token arguments, handling factory token resolution and validation. * * @param token The token to validate * @param args Optional arguments * @returns [error, { actualToken, validatedArgs }] */ validateAndResolveTokenArgs(token: AnyInjectableType, args?: any): [DIError | undefined, { actualToken: InjectionTokenType; validatedArgs?: any; }]; } //#endregion //#region src/internal/holder/unified-storage.d.mts /** * Unified storage implementation that works the same way regardless of scope. * Replaces RequestContext, HolderManager, SingletonStorage, RequestStorage. * * Scope is just metadata - storage operations are identical for all scopes. * Different storage instances are just isolated storage spaces. */ declare class UnifiedStorage implements IHolderStorage { readonly scope: InjectableScope; private readonly holders; /** * Reverse dependency index: maps a dependency name to the set of holder names that depend on it. * This allows O(1) lookup of dependents instead of O(n) iteration. */ private readonly dependents; constructor(scope?: InjectableScope); get(instanceName: string): HolderGetResult; set(instanceName: string, holder: InstanceHolder): void; delete(instanceName: string): boolean; createHolder(instanceName: string, type: InjectableType, deps: Set): [ReturnType>, InstanceHolder]; storeInstance(instanceName: string, instance: unknown): void; handles(scope: InjectableScope): boolean; getAllNames(): string[]; forEach(callback: (name: string, holder: InstanceHolder) => void): void; findByInstance(instance: unknown): InstanceHolder | null; findDependents(instanceName: string): string[]; /** * Updates dependency references when instance names change. * Used during scope upgrades when instance names are regenerated with requestId. * * @param oldName The old instance name * @param newName The new instance name */ updateDependencyReference(oldName: string, newName: string): void; /** * Registers a holder's dependencies in the reverse index. */ private registerDependencies; /** * Removes a holder from the reverse dependency index. */ private removeFromDependentsIndex; } //#endregion //#region src/container/abstract-container.d.mts /** * Abstract base class for dependency injection containers. * * Provides shared implementation for common container operations. * Both Container and ScopedContainer extend this class. */ declare abstract class AbstractContainer implements IContainer { /** * The default scope used when adding instances without explicit registration. */ protected abstract readonly defaultScope: InjectableScope; /** * The request ID for scoped containers, undefined for root container. */ protected abstract readonly requestId: string | undefined; /** * Gets the storage for this container. */ abstract getStorage(): UnifiedStorage; /** * Gets the registry for this container. */ protected abstract getRegistry(): Registry; /** * Gets the token resolver. */ protected abstract getTokenResolver(): TokenResolver; /** * Gets the name resolver. */ protected abstract getNameResolver(): NameResolver; /** * Gets the service invalidator. */ protected abstract getServiceInvalidator(): ServiceInvalidator; /** * Gets an instance from the container. */ abstract get(token: T): InstanceType extends Factorable ? Promise : Promise>; abstract get, R>(token: T, args: R): Promise>; abstract get(token: InjectionToken, args: z.input): Promise; abstract get(token: InjectionToken): R extends false ? Promise : S extends ZodType ? `Error: Your token requires args: ${Join, ', '>}` : 'Error: Your token requires args'; abstract get(token: InjectionToken): Promise; abstract get(token: BoundInjectionToken): Promise; abstract get(token: FactoryInjectionToken): Promise; /** * Invalidates a service and its dependencies. */ abstract invalidate(service: unknown): Promise; /** * Disposes the container and cleans up all resources. */ abstract dispose(): Promise; /** * Calculates the instance name for a given token and optional arguments. * * @internal * @param token The class type, InjectionToken, BoundInjectionToken, or FactoryInjectionToken * @param args Optional arguments (ignored for BoundInjectionToken which uses its bound value) * @returns The calculated instance name string, or null if the token is a FactoryInjectionToken that is not yet resolved */ calculateInstanceName(token: ClassType | InjectionToken | BoundInjectionToken | FactoryInjectionToken, args?: unknown): string | null; /** * Checks if a service is registered in the container. */ isRegistered(token: any): boolean; /** * Waits for all pending operations to complete. */ ready(): Promise; /** * @internal * Attempts to get an instance synchronously if it already exists. */ tryGetSync(token: any, args?: any): T | null; /** * @internal * Internal method for getting instances synchronously with configurable storage. */ protected tryGetSyncFromStorage(token: any, args: any, storage: UnifiedStorage, requestId?: string): T | null; /** * Adds an instance to the container. * Accepts class types, InjectionTokens, and BoundInjectionTokens. * Rejects InjectionTokens with required schemas (use BoundInjectionToken instead). * * @param token The class type, InjectionToken, or BoundInjectionToken to register the instance for * @param instance The instance to store */ addInstance(token: ClassType | InjectionToken | BoundInjectionToken, instance: T): void; /** * @internal * Internal method for adding instances with configurable scope and storage. */ protected addInstanceToStorage(token: ClassType | InjectionToken | BoundInjectionToken, instance: T, storage: UnifiedStorage, scope: InjectableScope, requestId?: string): void; } //#endregion //#region src/container/scoped-container.d.mts /** * Request-scoped dependency injection container. * * Wraps a parent Container and provides isolated request-scoped instances * while delegating singleton and transient resolution to the parent. * This design eliminates race conditions that can occur with async operations * when multiple requests are processed concurrently. */ declare class ScopedContainer extends AbstractContainer { private readonly parent; private readonly registry; readonly requestId: string; protected readonly defaultScope = InjectableScope.Request; private readonly storage; private disposed; private readonly metadata; constructor(parent: Container, registry: Registry, requestId: string, metadata?: Record); getStorage(): UnifiedStorage; protected getRegistry(): Registry; protected getTokenResolver(): TokenResolver; protected getNameResolver(): NameResolver; protected getServiceInvalidator(): ServiceInvalidator; /** * Gets the request ID for this scoped container. */ getRequestId(): string; /** * Gets the parent container. */ getParent(): Container; /** * Gets metadata from the request context. */ getMetadata(key: string): any | undefined; /** * Sets metadata on the request context. */ setMetadata(key: string, value: any): void; /** * Gets an instance from the container. * Request-scoped services are resolved from this container's storage. * All other services are delegated to the parent container. */ get(token: T): InstanceType extends Factorable ? Promise : Promise>; get, R>(token: T, args: R): Promise>; get(token: InjectionToken, args: z.input): Promise; get(token: InjectionToken): R extends false ? Promise : S extends ZodType ? `Error: Your token requires args: ${Join, ', '>}` : 'Error: Your token requires args'; get(token: InjectionToken): Promise; get(token: BoundInjectionToken): Promise; get(token: FactoryInjectionToken): Promise; /** * Invalidates a service and its dependencies. */ invalidate(service: unknown): Promise; /** * Disposes the container and cleans up all resources. * Alias for endRequest(). */ dispose(): Promise; /** * @internal * Attempts to get an instance synchronously if it already exists. * Checks request storage first, then delegates to parent. */ tryGetSync(token: any, args?: any): T | null; /** * Adds an instance to the container. * Overrides base class to check disposed state. */ addInstance(token: ClassType | InjectionToken | BoundInjectionToken, instance: T): void; /** * Ends the request and cleans up all request-scoped services. */ endRequest(): Promise; } //#endregion //#region src/internal/core/scope-tracker.d.mts /** * Component for tracking and handling scope upgrades. * * Detects when a Singleton service needs to be upgraded to Request scope * and coordinates the scope upgrade process atomically. */ declare class ScopeTracker { private readonly registry; private readonly nameResolver; private readonly logger; constructor(registry: Registry, nameResolver: NameResolver, logger?: Console | null); /** * Checks if a dependency requires scope upgrade and performs it if needed. * Called during service resolution when a dependency is resolved. * * @param currentServiceName - Name of the service being created * @param currentServiceScope - Current scope of the service being created * @param dependencyName - Name of the dependency being resolved * @param dependencyScope - Scope of the dependency * @param dependencyToken - Token of the dependency * @param singletonStorage - Singleton storage instance * @param requestStorage - Request storage instance (if in request context) * @param requestId - Request ID (if in request context) * @returns [needsUpgrade: boolean, newName?: string] - whether upgrade occurred and new name */ checkAndUpgradeScope(currentServiceName: string, currentServiceScope: InjectableScope, dependencyName: string, dependencyScope: InjectableScope, dependencyToken: InjectionToken, singletonStorage: IHolderStorage, requestStorage?: IHolderStorage, requestId?: string): [boolean, string?]; /** * Performs the actual scope upgrade from Singleton to Request. * This is the core migration logic. * * @param serviceName - Current service name (without requestId) * @param token - Service injection token * @param singletonStorage - Source storage * @param requestStorage - Target storage * @param requestId - Request ID to include in new name * @returns [success: boolean, newName?: string, error?: DIError] */ upgradeScopeToRequest(serviceName: string, token: InjectionToken, singletonStorage: IHolderStorage, requestStorage: IHolderStorage, requestId: string): Promise<[boolean, string?, DIError?]>; /** * Synchronous part of scope upgrade - handles immediate updates. * Async operations (like waiting for holder creation) should be done separately. */ private upgradeScopeToRequestSync; /** * Updates all parent dependencies to reference the new service name. * * @param oldName - Original service name * @param newName - New service name with requestId * @param singletonStorage - Singleton storage to check * @param requestStorage - Request storage to check */ updateParentDependencies(oldName: string, newName: string, singletonStorage: IHolderStorage, requestStorage?: IHolderStorage): void; } //#endregion //#region src/internal/core/service-initializer.d.mts /** * Creates service instances from registry records. * * Handles both class-based (@Injectable) and factory-based (@Factory) services, * managing the instantiation lifecycle including lifecycle hook invocation. */ declare class ServiceInitializer { private readonly injectors; constructor(injectors: Injectors); /** * Instantiates a service based on its registry record. * @param ctx The factory context for dependency injection * @param record The factory record from the registry * @param args Optional arguments for the service * @returns Promise resolving to [undefined, instance] or [error] */ instantiateService(ctx: ServiceInitializationContext, record: FactoryRecord, args?: any): Promise<[undefined, T] | [DIError]>; /** * Instantiates a class-based service (Injectable decorator). * @param ctx The factory context for dependency injection * @param record The factory record from the registry * @param args Optional arguments for the service constructor * @returns Promise resolving to [undefined, instance] or [error] */ private instantiateClass; /** * Instantiates a factory-based service (Factory decorator). * @param ctx The factory context for dependency injection * @param record The factory record from the registry * @param args Optional arguments for the factory * @returns Promise resolving to [undefined, instance] or [error] */ private instantiateFactory; } //#endregion //#region src/internal/core/instance-resolver.d.mts /** * Resolves instances from tokens, handling caching, creation, and scope rules. * * Uses unified storage for both singleton and request-scoped services. * Coordinates with ServiceInitializer for actual service creation. * Integrates ScopeTracker for automatic scope upgrades. */ declare class InstanceResolver { private readonly registry; private readonly storage; private readonly serviceInitializer; private readonly tokenResolver; private readonly nameResolver; private readonly scopeTracker; private readonly serviceInvalidator; private readonly eventBus; private readonly logger; constructor(registry: Registry, storage: IHolderStorage, serviceInitializer: ServiceInitializer, tokenResolver: TokenResolver, nameResolver: NameResolver, scopeTracker: ScopeTracker, serviceInvalidator: ServiceInvalidator, eventBus: LifecycleEventBus, logger?: Console | null); /** * Resolves an instance for the given token and arguments. * This method is used for singleton and transient services. * * @param token The injection token * @param args Optional arguments * @param contextContainer The container to use for creating context * @param requestStorage Optional request storage (for scope upgrades) * @param requestId Optional request ID (for scope upgrades) */ resolveInstance(token: AnyInjectableType, args: any, contextContainer: IContainer, requestStorage?: IHolderStorage, requestId?: string): Promise<[undefined, any] | [DIError]>; /** * Resolves a request-scoped instance for a ScopedContainer. * The service will be stored in the ScopedContainer's request storage. * * @param token The injection token * @param args Optional arguments * @param scopedContainer The ScopedContainer that owns the request context */ resolveRequestScopedInstance(token: AnyInjectableType, args: any, scopedContainer: ScopedContainer): Promise<[undefined, any] | [DIError]>; /** * Unified resolution method that works with any IHolderStorage. * This eliminates duplication between singleton and request-scoped resolution. * * IMPORTANT: The check-and-store logic is carefully designed to avoid race conditions. * The storage check and holder creation must happen synchronously (no awaits between). * * @param token The injection token * @param args Optional arguments * @param contextContainer The container for context * @param storage The storage strategy to use * @param scopedContainer Optional scoped container for request-scoped services * @param requestStorage Optional request storage (for scope upgrades) * @param requestId Optional request ID (for scope upgrades) */ private resolveWithStorage; /** * Internal method to resolve token args and create instance name. * Handles factory token resolution and validation. */ private resolveTokenAndPrepareInstanceName; /** * Handles storage error states (destroying, error, etc.). * Returns a result if handled, null if should proceed with creation. */ private handleStorageError; /** * Creates a new instance and stores it using the provided storage strategy. * This unified method replaces instantiateServiceFromRegistry and createRequestScopedInstance. * * For transient services, the instance is created but not stored (no caching). */ private createAndStoreInstance; /** * Creates a transient instance without storage or locking. * Each call creates a new instance. */ private createTransientInstance; /** * Handles successful service instantiation. */ private handleInstantiationSuccess; /** * Handles service instantiation errors. */ private handleInstantiationError; /** * Handles instantiation result (success or error). */ private handleInstantiationResult; /** * Waits for an instance holder to be ready and returns the appropriate result. * * @param holder The holder to wait for * @param waiterHolder Optional holder that is doing the waiting (for circular dependency detection) * @param getHolder Optional function to retrieve holders by name (required if waiterHolder is provided) */ private waitForInstanceReady; /** * Creates a ServiceInitializationContext for service instantiation. */ private createServiceInitializationContext; } //#endregion //#region src/container/container.d.mts /** * Main dependency injection container. * * Provides a simplified public API for dependency injection. * Handles singleton and transient services directly, * while request-scoped services require using beginRequest() to create a ScopedContainer. */ declare class Container extends AbstractContainer { protected readonly registry: Registry; protected readonly logger: Console | null; protected readonly injectors: Injectors; protected readonly defaultScope = InjectableScope.Singleton; protected readonly requestId: undefined; private readonly storage; private readonly serviceInitializer; private readonly serviceInvalidator; private readonly tokenResolver; private readonly nameResolver; private readonly scopeTracker; private readonly eventBus; private readonly instanceResolver; private readonly activeRequestIds; constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors); private registerSelf; /** * Gets an instance from the container. * NOTE: Request-scoped services cannot be resolved directly from Container. * Use beginRequest() to create a ScopedContainer for request-scoped services. */ get(token: T): InstanceType extends Factorable ? Promise : Promise>; get, R>(token: T, args: R): Promise>; get(token: InjectionToken, args: z.input): Promise; get(token: InjectionToken): R extends false ? Promise : S extends ZodType ? `Error: Your token requires args: ${Join, ', '>}` : 'Error: Your token requires args'; get(token: InjectionToken): Promise; get(token: BoundInjectionToken): Promise; get(token: FactoryInjectionToken): Promise; /** * Invalidates a service and its dependencies. */ invalidate(service: unknown): Promise; /** * Disposes the container and cleans up all resources. */ dispose(): Promise; /** * @internal * Attempts to get an instance synchronously if it already exists. * Overrides base class to support requestId parameter for ScopedContainer compatibility. */ tryGetSync(token: any, args?: any, requestId?: string): T | null; /** * Begins a new request context and returns a ScopedContainer. */ beginRequest(requestId: string, metadata?: Record): ScopedContainer; /** * Gets all active request IDs. */ getActiveRequestIds(): ReadonlySet; /** * Checks if a request is active. */ hasActiveRequest(requestId: string): boolean; /** * Removes a request ID from active requests. * Called by ScopedContainer when request ends. */ removeRequestId(requestId: string): void; getStorage(): UnifiedStorage; getServiceInitializer(): ServiceInitializer; getServiceInvalidator(): ServiceInvalidator; getTokenResolver(): TokenResolver; getNameResolver(): NameResolver; getScopeTracker(): ScopeTracker; getEventBus(): LifecycleEventBus; getRegistry(): Registry; getInstanceResolver(): InstanceResolver; } //#endregion export { NameResolver as C, DIErrorCode as S, InstanceHolderCreating as _, ScopedContainer as a, InstanceStatus as b, ClearAllOptions as c, LifecycleEventBus as d, HolderGetResult as f, InstanceHolderCreated as g, InstanceHolder as h, ScopeTracker as i, InvalidationOptions as l, InstanceDestroyListener as m, InstanceResolver as n, UnifiedStorage as o, IHolderStorage as p, ServiceInitializer as r, TokenResolver as s, Container as t, ServiceInvalidator as u, InstanceHolderDestroying as v, DIError as x, InstanceHolderError as y }; //# sourceMappingURL=container-r1KP4F-n.d.cts.map