import { Provider, Record, Token, Type } from './types'; /** * The options for an {@link Injector}. */ export interface InjectorOptions { /** * Whether to support circular dependencies or not. */ allowCircularDependencies?: boolean; /** * Whether to allow dependencies to inject the current injector or not. */ allowInjectorInjection?: boolean; } /** * Does all the Dependency Injection. */ export declare class Injector { private readonly parentInjector; private readonly pending; private readonly instantiated; private readonly records; private readonly options; /** * Boolean to be used to prevent calls to {@link Injector.handlePendingRecords} to do something. */ protected runHandlePendingRecords: boolean; /** * Creates a new Injector. * * @param options The options for this injector * @param parentInjector An optional parent injector. It is recommmended to use the {@link Injector.createChildInjector} method instead */ constructor(options?: InjectorOptions, parentInjector?: Injector); /** * Returns this injector. * * @param token A token that indicates to return this Injector * * @returns This injector * * @throws {@link IllegalArgumentError} When this Injector is not an instance of the given Injector token * @throws {@link IllegalAccessError} When this Injector has disabled the {@link InjectorOptions.allowInjectorInjection} option */ get(token: Type): T; /** * Returns a tokens value by first checking records in this Injector and then checking the ones in the parent Injector if it exists. * If no record could be found then *null* is returned. * In theory a record could have been found where the value is set to *null*. * To detect that use the {@link Injector.has} method. * * @param token The token to be checked * * @returns The tokens value or *null* if no record could be found * * @throws {@link InstantiationError} When the instantiation of a multi-record fails * @throws {@link DependencyError} When there is an issue while injecting dependencies for a multi-record */ get(token: Type | Exclude>): T; /** * Returns whether a Token can be provided by this Injector or a parent of this Injector. * * @param token The token to check * * @returns true if the token can be provided, false if otherwise */ has(token: Token): boolean; /** * Returns whether a token is known in this Injector or a parent Injector. * The difference between {@link Injector.has} is that the pending and instantiated maps of each Injector are checked too. * * @param token The token to check * * @returns true if the token is known, false if otherwise */ knownToken(token: Token): boolean; /** * Returns whether this Injector has a parent or not. * * @returns true if this Injector has a parent, false if otherwise */ hasParent(): boolean; /** * Adds a {@link Provider} to this {@link Injector}. * * @param provider The {@link Provider} to be added * * @throws {@link DependencyError} When the {@link Provider} is invalid * @throws {@link DependencyError} When {@link InstanceProvider.useInstance} does not have a constructor * @throws {@link DependencyError} When {@link InstanceProvider.useInstance}s class has {@link Injectable.multi} declared * @throws {@link DependencyError} When the {@link Token} is already known by this {@link Injector} or a parent {@link Injector} * * @see {@link Provider}, {@link ValueProvider}, {@link ClassProvider}, {@link InstanceProvider}, {@link FactoryProvider}, {@link ExistingProvider}, {@link TypeProvider} */ provide(provider: Provider): void; /** * Verifies this Injector and throws an error if one or more records are pending. * This method does **NOT** verify the parent Injector. * * @throws {@link IllegalStateError} When one or more records are pending including detailed information about the dependency map */ verify(): void; /** * Creates a new child Injector. * * @param options The options for this injector * @returns A new Injector instance */ createChildInjector(options?: InjectorOptions): Injector; /** * Resolves and creates dependencies starting from one {@link Type} and recursively checking other {@link Type} references and also adding them. * If there are any non-{@link Type} dependencies those will be skipped but this method will not throw an error on missing dependencies either. * If a {@link Type} has already been provided beforehand this method will not create a new {@link Record} for it but still resolve it's dependencies. * Use the {@link Injector.verify} method to check whether everything has been resolved or not. * * @param type The {@link Type} (class) to start resolving at */ resolveAndCreate(type: Type): void; protected resolveAdditionalDependencies(record: Record): Array; protected onRecordsLinked(records: Array): void; protected onRecordInstantiated(record: Record, multiInstance?: any): void; protected stringifyToken(token: Token): string; protected getRecord(token: Token, checkParent?: boolean): Record; protected handlePendingRecords(): void; private resolveAndCreateRecursively; private getFromMap; private instantiateRecord; private detectCircularDependency; private _detectCircularDependency; private getMissingDependencies; private markDependentsAsMissing; private linkRecord; private linkRecords; private resolveDependencies; private resolveInjectableMeta; }