import { AnyInjectableType } from "../../token/injection-token.mjs"; import { IContainer } from "../../interfaces/container.interface.mjs"; import { Registry } from "../../token/registry.mjs"; import { NameResolver } from "./name-resolver.mjs"; import { DIError } from "../../errors/di-error.mjs"; import { IHolderStorage } from "../holder/holder-storage.interface.mjs"; import { LifecycleEventBus } from "../lifecycle/lifecycle-event-bus.mjs"; import { ServiceInvalidator } from "./service-invalidator.mjs"; import { TokenResolver } from "./token-resolver.mjs"; import { ScopedContainer } from "../../container/scoped-container.mjs"; import { ScopeTracker } from "./scope-tracker.mjs"; import { ServiceInitializer } from "./service-initializer.mjs"; //#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 export { InstanceResolver }; //# sourceMappingURL=instance-resolver.d.mts.map