import { AwilixContainer, FunctionReturning } from './container'; import { InjectionModeType } from './injection-mode'; import { LifetimeType } from './lifetime'; /** * RESOLVER symbol can be used by modules loaded by * `loadModules` to configure their lifetime, injection mode, etc. */ export declare const RESOLVER: unique symbol; /** * Gets passed the container and is expected to return an object * whose properties are accessible at construction time for the * configured resolver. * * @type {Function} */ export type InjectorFunction = (container: AwilixContainer) => object; /** * A resolver object returned by asClass(), asFunction() or asValue(). */ export interface Resolver extends ResolverOptions { resolve(container: AwilixContainer): T; } /** * A resolver object created by asClass() or asFunction(). */ export interface BuildResolver extends Resolver, BuildResolverOptions { injectionMode?: InjectionModeType; injector?: InjectorFunction; setLifetime(lifetime: LifetimeType): this; setInjectionMode(mode: InjectionModeType): this; singleton(): this; scoped(): this; transient(): this; proxy(): this; classic(): this; inject(injector: InjectorFunction): this; } /** * Options for disposable resolvers. */ export interface DisposableResolverOptions extends ResolverOptions { dispose?: Disposer; } /** * Disposable resolver. */ export interface DisposableResolver extends Resolver, DisposableResolverOptions { disposer(dispose: Disposer): this; } /** * Disposer function type. */ export type Disposer = (value: T) => any | Promise; /** * The options when registering a class, function or value. * @type RegistrationOptions */ export interface ResolverOptions { /** * Only used for inline configuration with `loadModules`. */ name?: string; /** * Lifetime setting. */ lifetime?: LifetimeType; /** * Registration function to use. Only used for inline configuration with `loadModules`. */ register?: (...args: any[]) => Resolver; /** * True if this resolver should be excluded from lifetime leak checking. Used by resolvers that * wish to uphold the anti-leakage contract themselves. Defaults to false. */ isLeakSafe?: boolean; } /** * Builder resolver options. */ export interface BuildResolverOptions extends ResolverOptions, DisposableResolverOptions { /** * Resolution mode. */ injectionMode?: InjectionModeType; /** * Injector function to provide additional parameters. */ injector?: InjectorFunction; } /** * A class constructor. For example: * * class MyClass {} * * container.registerClass('myClass', MyClass) * ^^^^^^^ */ export type Constructor = { new (...args: any[]): T; }; /** * Creates a simple value resolver where the given value will always be resolved. The value is * marked as leak-safe since in strict mode, the value will only be resolved when it is not leaking * upwards from a child scope to a parent singleton. * * @param {string} name The name to register the value as. * * @param {*} value The value to resolve. * * @return {object} The resolver. */ export declare function asValue(value: T): Resolver; /** * Creates a factory resolver, where the given factory function * will be invoked with `new` when requested. * * @param {string} name * The name to register the value as. * * @param {Function} fn * The function to register. * * @param {object} opts * Additional options for the resolver. * * @return {object} * The resolver. */ export declare function asFunction(fn: FunctionReturning, opts?: BuildResolverOptions): BuildResolver & DisposableResolver; /** * Like a factory resolver, but for classes that require `new`. * * @param {string} name * The name to register the value as. * * @param {Class} Type * The function to register. * * @param {object} opts * Additional options for the resolver. * * @return {object} * The resolver. */ export declare function asClass(Type: Constructor, opts?: BuildResolverOptions): BuildResolver & DisposableResolver; /** * Resolves to the specified registration. Marked as leak-safe since the alias target is what should * be checked for lifetime leaks. */ export declare function aliasTo(name: Parameters[0]): Resolver; /** * Given an options object, creates a fluid interface * to manage it. * * @param {*} obj * The object to return. * * @return {object} * The interface. */ export declare function createBuildResolver>(obj: B): BuildResolver & B; /** * Given a resolver, returns an object with methods to manage the disposer * function. * @param obj */ export declare function createDisposableResolver>(obj: B): DisposableResolver & B;