import { Implementation } from '../typing/implementation'; import { NewableService } from '../typing/newable-service'; import { Provider } from './Provider'; /** * The dependency injector used to register and retrieve services */ export declare class Injector { private readonly container; private readonly singletonInstances; private readonly registeredTypes; static readonly CONSTRUCTOR_NAME_SYMBOL_IDENTIFIER = "___CTOR_NAME___"; static readonly CONSTRUCTOR_NAME_SYMBOL: unique symbol; /** * Register an implementation to an optional type * @param implementationType The implementation type * @param mappedType The type on which the implementation is mapped to. * This type can be a class or an abstract class, but it cannot be an interface * since in TS interfaces are not compiled into the JS output. */ registerSingleton(implementationType: Implementation, mappedType?: Function & { prototype: T; }): void; /** * Register a provider that will provide instances of a type. * The provider can have dependencies, they will be resolved as in any other implementation type * @param providerType The provider type that will create instances of a type * @param mappedType The type that the provider will create instances of */ registerSingletonProvider(providerType: NewableService>, mappedType: Function & { prototype: T; }): void; /** * Retrieve an instance of a type that has been registered * (cf {@link registerSingleton} and {@link registerSingletonProvider}) * @param type The type for which an instance of is required */ getInstance(type: Function & { prototype: T; }): T; /** * Verify if an instance of a type that has been registered * (cf {@link registerSingleton} and {@link registerSingletonProvider}) * @param type The type for which the registration test is wanted */ hasInstance(type: Function & { prototype: T; }): boolean; /** * Initialize all singleton instances: i.e. all constructors of mapped types implementation will be called. * This should be called after all types have been declared. * * This is useful: * - To make sure no construction errors arise as soon as the application starts: * it is better to discover these errors soon * - To start services which observe data from other services, * initialize everything enables to make sure all instances are doing their job */ initializeSingletonInstances(): void; private static getTypeName; }