import { Container } from './container.js'; import type { FactoryProvider } from './types/factory-provider.js'; import type { InjectableClass } from './types/injectable-class.js'; import type { RegistrationOptions } from './types/options.js'; import type { Token } from './types/tokens.js'; type ValidateArity any, Deps extends readonly Token[]> = Deps['length'] extends ConstructorParameters['length'] ? ConstructorParameters['length'] extends Deps['length'] ? unknown : never : never; /** * ContainerBuilder is the class you use to configure a Container. * * The ContainerBuilder has 2 main responsibilities: * 1. Collect all provider registrations, which can be defined in any order. * - Handled by register* methods. * 2. Instantiate instances and register them in a new Container. * - Handled by `.build()`. * * The ContainerBuilder does a topological sort to ensure that instances are created and destroyed * in the correct order (e.g. all of a providers dependencies must be created before that * provider's instance can be created, and destruction needs to happen in the opposite order). */ export declare class ContainerBuilder { private readonly registrations; /** * Register a static value. */ registerValue(token: Token, value: T): this; /** * Declare a scoped value token whose value will be provided at scope creation time. * Scoped providers can depend on this token; the actual value is supplied via * `container.createScopeBuilder().provideValue(token, value).build()`. */ registerScopedValue(token: Token): this; /** * Register a class with static deps property. * Dependencies are resolved automatically during build(). * Type safety between the deps array and constructor params is enforced at this method. */ registerClass[] = readonly [], C extends InjectableClass = InjectableClass>(Class: C & InjectableClass & ValidateArity, options?: RegistrationOptions): this; /** * Register a factory provider, which can be async or sync and can inject other dependencies. */ registerFactory[], DestroyDeps extends readonly Token[]>(provider: FactoryProvider, options?: RegistrationOptions): this; /** * Merge providers from another container. * * This is useful for creating standalone packages/libraries that export a ContainerBuilder. * You can use `merge` to bring these standalone packages together into a single Container. */ merge(other: ContainerBuilder): this; /** * Check if a token has been registered. */ has(token: Token): boolean; /** * Override an existing provider with a value; intended for mocking during tests. * Only works for singleton providers. For scoped providers, use overrideFactory instead. */ overrideValue(token: Token, value: T): this; /** * Override an existing provider with a class; intended for mocking during tests. * Preserves the original provider's scope. */ overrideClass[] = readonly [], C extends InjectableClass = InjectableClass>(token: Token, Class: C & InjectableClass & ValidateArity): this; /** * Override an existing provider with a factory; intended for mocking during tests. * Preserves the original provider's scope. */ overrideFactory[], DestroyDeps extends readonly Token[]>(provider: FactoryProvider): this; private assertTokenRegistered; /** * Build the container - topologically sorts providers and instantiates singletons. * Scoped providers are validated but not instantiated - they're stored for later use in Scopes. * By default, also initializes the container (calls onInit on all services). */ build(options?: { init?: boolean; }): Promise; /** * Topologically sort providers by their dependencies using Kahn's algorithm. * * This ensures that dependent providers are created and initialized BEFORE the providers that * depend on them, and that dependent providers are destroyed AFTER providers that depend on them. * * Also validates that singleton providers do not depend on scoped providers. */ private topologicalSort; /** * Find a cycle path using DFS with coloring. * Returns the cycle as an array of tokens ending with the repeated token. */ private findCyclePath; private addRegistration; private isScoped; private isSingleton; /** * Resolve dependencies from the instances map. */ private resolveDeps; } export {}; //# sourceMappingURL=container-builder.d.ts.map