import { ClassType, Type } from "../type"; import { InjectionMapping } from "./data/InjectionMapping"; import { EventDispatcher } from "../eventDispatcher/EventDispatcher"; import { InjectionToken } from "./data/InjectionToken"; /** * Dependency provider implementation class */ export declare class Injector extends EventDispatcher { readonly parent: Injector; private readonly MASTER_SEAL_KEY; private _destroyed; private mappings; constructor(parent?: Injector); /** * Whether Injector is destroyed */ get destroyed(): boolean; /** * Create a new sub-injector with current instance set as its parent. */ createSubInjector(): Injector; /** * Create injector mapping. * @param type The class type describing the mapping * @returns {InjectionMapping} * @throws Error in case if method is invoked on destroyed instance * @throws Error in case if attempt to override sealed mapping is encountered */ map(type: ClassType | InjectionToken): InjectionMapping; /** * Removes the mapping described by the given type from current injector. * @param type The class type describing the mapping * @throws Error in case if method i invoked on destroyed instance * @throws Error if unknown mapping is attempted to be unmapped * @throws Error if sealed mapping is attempted to be unmapped */ unMap(type: ClassType | InjectionToken): void; /** * Does this injector have a direct mapping for the given type? * @param type The type * @return True if the mapping exists * @throws Error in case if method i invoked on destroyed instance */ hasDirectMapping(type: ClassType | InjectionToken): boolean; /** * Does this injector (or any parents) have a mapping for the given type? * @param type The type * @return True if the mapping exists * @throws Error in case if method is invoked on destroyed instance */ hasMapping(type: ClassType | InjectionToken): boolean; /** * Returns the mapping for the specified dependency class. * Note that getMapping will only return mappings in exactly this injector, not ones mapped in an ancestor injector. To get mappings from ancestor injectors, query them * using parent. * This restriction is in place to prevent accidental changing of mappings in ancestor injectors where only the child's response is meant to be altered. * @param type The type of the dependency to return the mapping for * @return The mapping for the specified dependency class * @throws Error in case if method i invoked on destroyed instance * @throws Error when no mapping was found for the specified dependency */ getMapping(type: ClassType | InjectionToken): InjectionMapping; /** * Get or created injected instance mapped for required type. * Invoking this method will return existing mapping or create new one in case if there have been no requests for this mapping or it's not mapped with instantiate call. * @param {ClassType} type * @throws Error in case if method is invoked on destroyed instance * @throws Error when no mapping was found for the specified dependency */ get(type: ClassType | InjectionToken): T; /** * Create instance of given type with constructor argument values injected, if any are described by metadata, and injected properties filled with values from Injector, * if there are any. * Invoking this method will also invoke any methods marked with @PostConstruct just as injected properties will be filled in. * @param type Instance type to be created. * @param postponePostConstruct Flag which is set true will postpone post construct method invocation for smallest amount of time possible in order to make mapped value * available within injector as PostConstruct is called. * @throws Error in case if method i invoked on destroyed instance * @throws Error in case if some Injector mapping could not be found. */ instantiateInstance(type: Type, postponePostConstruct?: boolean): T; /** * Inspect given type and fill in type properties, clients for Injected values and invoke methods described with @PostConstruct if there are any. * @param target The instance to inject into * @param postponePostConstruct Flag which is set true will postpone post construct method invocation for smallest amount of time possible in order to make mapped value * available within injector as PostConstruct is called * @throws Error in case if method i invoked on destroyed instance * @throws Error in case if some Injector mapping could not be found. */ injectInto(target: T, postponePostConstruct?: boolean): T; /** * Check if some instance has pre destroy methods defined and if so - invoke them * @param target instance of injected values client * @throws Error in case if method is invoked on destroyed instance */ destroyInstance(target: any): void; /** * Destroy injector and all of its direct mappings. * @throws Error in case if Injector is already destroyed */ destroy(): void; /** * Throw error if Injector is already destroyed. */ private throwErrorIfDestroyed; private getIndirectTypeMapping; }