import { HashMap } from "@azera/util/is"; import { ContainerValue, Factory, IAutoTagger, IContainer, IDefinition, IMethod, Injectable, Invokable, MockMethod, Service, Constructor } from "./types"; export declare const FACTORY_REGEX: RegExp; export declare const SERVICE_REGEX: RegExp; /** * Dependency Injection Container * @author Masoud Zohrabi */ export declare class Container implements IContainer { /** * Check if decorated class was inherited from another decorated class * @param target Class */ static isInheritedServiceDecorator(target: Function): boolean; /** * Prepare class if inherited from service decorated class * @param target Class */ static checkInheritance(target: Function): void; /** * Invoked services in-memory cache */ private instances; /** * Container parameters collection */ private params; /** * Declared service definitions */ private services; /** * Tag extractor functions */ private autoTags; /** * Type factories */ private factories; /** * Container-specified class definitions */ private types; /** * Imported things */ private imported; /** Exception on async dependencies when invoke called synchrounosly */ strictAsync: boolean; constructor(services?: HashMap, parameters?: HashMap, autoTags?: IAutoTagger[]); /** * Get container parameters */ getParameters(): HashMap; /** * Build service from factory * @param factory Factory * @param _stack Stack * @internal */ private buildFromFactory; /** * Resolve import * @param item Path or Function to import * @internal */ private resolveImport; /** * Resolve definition imports * @param service Service definition * @internal */ private resolveImports; /** * Resolve (build) service definition * @param definition Service definition * @param _stack Resolving stack * @param options Options * @internal */ private resolveDefinition; private _throwError; /** * Build service by name * @param name Service name * @param stack Injection stack ( for debugging ) * @throws ServiceNotFoundError * @internal */ private getService; /** * Get service/parameters * @param name Service or paremeter name * @param stack Injection stack * @internal */ private _get; get(service: T): T | undefined; get(name: string): T | undefined; /** * Build tagged services * @param tag Tag */ getByTag(tag: string): T[]; getByTagAsync(tag: string): Promise; /** * Get tagged services definitions * @param tag Tag */ findByTag(tag: string): IDefinition[]; /** * Make an method injectable for later use * @param context Method context (Class instance) * @param method Method name */ invokeLater(context: Constructor, method: M): MockMethod; invokeLater(context: T, method: M): MockMethod; invokeLater(callable: Injectable): (...params: any[]) => R; /** * Make an method injectable for later use * @param context Method context (Class instance) * @param method Method name */ invokeLaterAsync(context: Constructor, method: M): MockMethod; invokeLaterAsync(context: T, method: M): MockMethod; invokeLaterAsync(callable: Injectable): (...params: any[]) => Promise; /** * Invoke a function and resolve its dependencies * @param value Invokable value */ invoke(value: Invokable): T; invokeAsync(value: Invokable): Promise; /** * * @param value Invokable value * @param stack Injection stack * @param options */ private _invoke; /** * Set parameter value * @param name Parameter name * @param value Value */ setParameter(name: string, value: any): this; /** * Set parameters value * @param params Parameters */ setParameters(params: { [key: string]: any; }): this; /** * Set factory for a function * @param type Type * @param factory Factory */ setFactory(type: Function | string, factory: Factory): this; /** * Set alias for a type * @param type Type * @param alias Alias value */ setAlias(type: Function, alias: any): this; /** * Get overrided service definition * @param type Type */ getType(type: Function): IDefinition | undefined; /** * Set batch services and parameters * @param values Services and Parameters */ set(values: { [name: string]: IDefinition | ContainerValue; }): this; /** * Set service/parameter * @param name Service/Parameter name * @param value */ set(name: string, value: IDefinition | ContainerValue): this; /** * Container-scope class definition * @param type Type/Class * @param definition Definition */ set(type: Function, definition: Partial): this; /** * Get service built-in definition * @param target Class/Function */ getDefinition(target: string | IMethod | Injectable): IDefinition; /** * Add definition to container * @param definition Definition */ addDefinition(definition: IDefinition): this; /** * Get parameter value * @param name Parameter name */ getParameter(name: string): any; /** * Check parameter exists * @param name Parameter name */ hasParameter(name: string): boolean; /** * Check for service definition exist * @param name Service name */ has(name: string): boolean; /** * Add Auto-tagger * @param tagger Auto-tagger */ autoTag(tagger: IAutoTagger): this; autoTag(base: Function, tags: string[]): this; /** * Declare class or function to container */ add(...services: Function[]): this; /** * Get declared definitions */ readonly definitions: HashMap>; /** * Return declared service names */ readonly names: string[]; /** * Get services count */ readonly size: number; [Symbol.iterator](): { next(): { done: boolean; value: string | undefined; }; }; } /** * Get injectable dependencies * @param value Injectable */ export declare function getDependencies(value: Injectable | IMethod): { deps: any; func: Function; }; /** * Create new container definition * @returns {IDefinition} */ export declare function Definition(definition: IDefinition): IDefinition; export declare function isFactory(value: any): value is Factory; export declare function isService(value: any): value is Service; export declare function isDefinition(value: any): value is IDefinition; export declare function Method(context: any, method: string): { context: any; method: string; }; export declare function isMethod(value: any): value is IMethod; export declare function isInternalClass(value: any): boolean;