import 'reflect-metadata'; import { TypedArray } from './array.js'; import { IBind, IContainer, IInjectDescriptor, IResolvedInjection, IToInject, AsyncService, ResolvableObject } from './interfaces.js'; import { Class, Factory } from './types.js'; import { EventEmitter } from './events.js'; import { Registry } from './registry.js'; import { ContainerCache } from './container-cache.js'; /** * Dependency injection container implementation */ export declare class Container extends EventEmitter implements IContainer { /** * Handles information about what is registered as what * eg. that class IConfiguration should be resolved as DatabaseConfiguration etc. */ private registry; /** * Singletons cache, objects that should be created only once are stored here. */ private cache; /** * Parent container if avaible */ private parent; /** * Child containers created from this container */ private children; /** * Returns container cache - map object with resolved classes as singletons */ get Cache(): ContainerCache; get Registry(): Registry; get Parent(): IContainer | undefined; constructor(parent?: IContainer); /** * Clears container registry and cache. shorthand for container.clearCache() && container.clearRegistry() */ clear(): void; dispose(): Promise; /** * clears container registered types information */ clearCache(): void; /** * Clears container resolved types */ clearRegistry(): void; /** * Get cache statistics for memory monitoring */ getCacheStats(): { size: number; entries: string[]; childrenCount: number; }; /** * Register class/interface to DI. * @param type - interface object to register * @throws {@link InvalidArgument} if type is null or undefined */ register(implementation: Class | Factory | ResolvableObject): IBind; unregister(implementation: string | Class | Factory | ResolvableObject): void; uncache(implementation: string | Class | TypedArray, parent?: boolean): void; /** * Creates child DI container. * */ child(): IContainer; /** * Gets already resolved services. Works only for singleton classes. * * Do not try to get service by factory func, it will always return null. * If you somehowe want to cache instances created by factory functions, * factory itself should do that somehow and end user should always resolve by * assigned type * * @param serviceName - name of service to get * @returns null if no service has been resolved at given name */ get(service: TypedArray, parent?: boolean): T[]; get(service: string | Class, parent?: boolean): T; hasRegistered(service: Class | string, parent?: boolean): boolean; /** * Checks if service is already resolved and exists in container cache. * NOTE: check is only valid for classes that are singletons. * * @param service - service name or class to check * @returns true if service instance already exists, otherwise false. * @throws {@link InvalidArgument} when service is null or empty */ isResolved(service: string | Class | TypedArray, parent?: boolean): boolean; /** * * Resolves single instance of class * * @param type - what to resolve, can be class definition or factory function * @param options - options passed to constructor / factory */ resolve(type: string, options?: unknown[], check?: boolean, tType?: Class): T; resolve(type: string, check?: boolean): T; /** * * Resolves single instance of class * * @param type - what to resolve, can be class definition or factory function * @param options - options passed to constructor / factory */ resolve(type: Class, options?: unknown[], check?: boolean): T extends AsyncService ? Promise : T; resolve(type: Class, check?: boolean): T extends AsyncService ? Promise : T; /** * * Resolves all instances of given class. Under single definition can be registered multiple implementations. * * @param type - typed array of specified type. since TS does not expose array metadata and type its uses TypedArray consctruct * @param options - options passed to constructor / factory * @param check - strict check if serivice is registered in container before resolving. Default behavior is to not check and resolve * */ resolve(type: TypedArray, options?: unknown[], check?: boolean): T extends AsyncService ? Promise : T[]; resolve(type: TypedArray, check?: boolean): T extends AsyncService ? Promise : T[]; getRegisteredTypes(service: string | Class | TypedArray, parent?: boolean): (Class | Factory)[]; private getCurrentType; private resolveType; protected getNewInstance(typeToCreate: Class | Factory, a?: IResolvedInjection[], options?: unknown[]): Promise | unknown; hasRegisteredType(source: Class | string, type: Class | string | TypedArray, parent?: boolean): boolean; protected resolveDependencies(toInject: IToInject[]): (Promise<{ autoinject: boolean; autoinjectKey: string | symbol; instance: any; }> | { autoinject: boolean; autoinjectKey: string | symbol; instance: any; })[] | Promise<({ autoinject: boolean; autoinjectKey: string | symbol; instance: any; } | { autoinject: boolean; autoinjectKey: string | symbol; instance: any; })[]>; extractDescriptor(type: Class): IInjectDescriptor; } //# sourceMappingURL=container.d.ts.map