import { InjectFactory } from './inject-factory'; import { ConstructorWithoutArguments, InjectableClass, InjectToken } from './inject-token'; import { BasicTypeInjector } from './basic-type-injector'; /** * Stable DI-Container that can be used everywhere. */ export declare class TypeInjector extends BasicTypeInjector { /** * Starts the construction of a new injector. * * ```typescript * TypeInjector.construct() * [...provide...] * .build(); * ``` * @returns TypeInjectorBuilder */ static construct(): TypeInjectorBuilder; } /** * Start configuration phase of a type injector. * * ```typescript * import { declareInjectToken, TypeInjector } from 'type-injector'; * * const injectToken = { * simpleValue: declareInjectToken('simple value'), * createdValue: declareInjectToken('created value'), * } * * const injector = TypeInjector.construct() * .provideValue(injectToken.simpleValue, 'Hello World!') * .provideFactory(injectToken.createdValue, { * deps: [injectToken.simpleValue], * create: (greeting: string) => `${greeting} Now it's: ${new Date()}`, * }) * .provideImplementation(Logger, RemoteLogger) * .build(); * ``` * * @see {@link TypeInjectorBuilder.provideValue} * @see {@link TypeInjectorBuilder.provideFactory} * @see {@link TypeInjectorBuilder.provideImplementation} */ export declare class TypeInjectorBuilder { protected _instances: Map, any>; protected _factories: Map, InjectFactory>; /** * Provide an existing value for a given token. * * This can be useful to provide an existing instance of a * service class, simple values like flags or configuration objects * from the environment. * * @typeParam T - Type defined by the token. Has to match the type of the value. * @param token - which will get used to inject the value * @param value - that will get returned for the token * @returns the Injector itself to allow chaining provides */ provideValue(token: InjectToken, value: T): TypeInjectorBuilder; /** * Provide a function that lazily creates a value. * * The provided function will be called the first time the token is requested. * * @typeParam T - Type defined by the token. Has to match the return type of the factory. * @param token - which will get used to inject the value * @param factory - that creates something that matches the type of the token * @returns the Injector itself to allow chaining provides */ provideFactory(token: InjectToken, factory: InjectFactory): TypeInjectorBuilder; /** * Provide an (alternative) implementation. * * This is a shortcut to create a factory for an implementation * that is injectable itself (has no constructor args / static inject config). * Like every factory it's called lazily on the first request of the token. * * @typeParam T - Type defined by the token. Has to match the type of the implementation. * @param token - which will get used to inject the value * @param impl - to instanciate as soon as it's requested the first time * @returns the Injector itself to allow chaining provides */ provideImplementation(token: InjectToken, impl: ConstructorWithoutArguments | InjectableClass): TypeInjectorBuilder; protected _closeBuilder(): void; /** * Finish configuration of the TypeInjector */ build(): TypeInjector; } //# sourceMappingURL=type-injector.d.ts.map