1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 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<T>(dependency: DependencyOrInstance<T>): 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<T>(dependency: Dependency<T>): 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<T>(identifier: DependencyIdentifier<T>): 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<T, P extends any[] = []>(cb: (accessor: IAccessor, ...args: P) => T, ...args: P): T;
- /**
- * Check if the injector could initialize a dependency.
- *
- * @param id Identifier of the dependency
- */
- has<T>(id: DependencyIdentifier<T>): boolean;
- get<T>(id: DependencyIdentifier<T>, lookUp?: LookUp): T;
- get<T>(id: DependencyIdentifier<T>, quantity: Quantity.MANY, lookUp?: LookUp): T[];
- get<T>(id: DependencyIdentifier<T>, quantity: Quantity.OPTIONAL, lookUp?: LookUp): T | null;
- get<T>(id: DependencyIdentifier<T>, quantity: Quantity.REQUIRED, lookUp?: LookUp): T;
- get<T>(id: DependencyIdentifier<T>, quantity?: Quantity, lookUp?: LookUp): T[] | T | null;
- get<T>(id: DependencyIdentifier<T>, quantityOrLookup?: Quantity | LookUp, lookUp?: LookUp): T[] | T | null;
- private _get;
- /**
- * Get a dependency in the async way.
- */
- getAsync<T>(id: DependencyIdentifier<T>): Promise<T>;
- /**
- * Instantiate a class. The created instance would not be held by the injector.
- */
- createInstance<T extends unknown[], U extends unknown[], C>(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;
- }
|