import { Dependency, DependencyOrInstance } from './dependencyCollection'; import { DependencyIdentifier } from './dependencyIdentifier'; import { LookUp, Quantity } from './types'; export interface IAccessor { get: Injector['get']; } /** * */ export declare class Injector { private readonly parent; private readonly dependencyCollection; private readonly resolvedDependencyCollection; private readonly children; private resolutionOngoing; private disposed; /** * Create a new `Injector` instance * @param dependencies Dependencies that should be resolved by this injector instance. * @param parent Optional parent injector. */ constructor(dependencies?: Dependency[], parent?: Injector | null); /** * Create a child inject with a set of dependencies. * @param dependencies Dependencies that should be resolved by the newly created child injector. * @returns The child injector. */ createChild(dependencies?: Dependency[]): Injector; /** * Dispose the injector and all dependencies held by this injector. Note that its child injectors will dispose first. */ dispose(): void; private deleteSelfFromParent; /** * Add a dependency or its instance into injector. It would throw an error if the dependency * has already been instantiated. * * @param dependency The dependency or an instance that would be add in the injector. */ add(dependency: DependencyOrInstance): void; /** * Replace an injection mapping for interface-based injection. It would throw an error if the dependency * has already been instantiated. * * @param dependency The dependency that will replace the already existed dependency. */ replace(dependency: Dependency): void; /** * Delete a dependency from an injector. It would throw an error when the deleted dependency * has already been instantiated. * * @param identifier The identifier of the dependency that is supposed to be deleted. */ delete(identifier: DependencyIdentifier): void; /** * Invoke a function with dependencies injected. The function could only get dependency from the injector * and other methods are not accessible for the function. * * @param cb the function to be executed * @param args arguments to be passed into the function * @returns the return value of the function */ invoke(cb: (accessor: IAccessor, ...args: P) => T, ...args: P): T; /** * Check if the injector could initialize a dependency. * * @param id Identifier of the dependency */ has(id: DependencyIdentifier): boolean; get(id: DependencyIdentifier, lookUp?: LookUp): T; get(id: DependencyIdentifier, quantity: Quantity.MANY, lookUp?: LookUp): T[]; get(id: DependencyIdentifier, quantity: Quantity.OPTIONAL, lookUp?: LookUp): T | null; get(id: DependencyIdentifier, quantity: Quantity.REQUIRED, lookUp?: LookUp): T; get(id: DependencyIdentifier, quantity?: Quantity, lookUp?: LookUp): T[] | T | null; get(id: DependencyIdentifier, quantityOrLookup?: Quantity | LookUp, lookUp?: LookUp): T[] | T | null; private _get; /** * Get a dependency in the async way. */ getAsync(id: DependencyIdentifier): Promise; /** * Instantiate a class. The created instance would not be held by the injector. */ createInstance(ctor: new (...args: [...T, ...U]) => C, ...customArgs: T): C; private _resolveDependency; private _resolveExisting; private _resolveValueDependency; private _resolveClass; private _resolveClassImpl; private _resolveFactory; private _resolveAsync; private _resolveAsyncImpl; private getValue; private createDependency; private markNewResolution; private markResolutionCompleted; private _ensureInjectorNotDisposed; }