ts-ioc-container
Version:
Typescript IoC container
49 lines (48 loc) • 2.15 kB
TypeScript
import { type CreateScopeOptions, type DependencyKey, type IContainer, type IContainerModule, type Instance, type RegisterOptions, ResolveManyOptions, type ResolveOneOptions, type Tag } from './IContainer';
import { type IInjector } from '../injector/IInjector';
import { type IProvider } from '../provider/IProvider';
import { type IRegistration } from '../registration/IRegistration';
import { type constructor } from '../utils';
export declare class Container implements IContainer {
isDisposed: boolean;
private parent;
private readonly scopes;
private readonly instances;
private readonly tags;
private readonly providerMap;
private readonly aliasMap;
private readonly registrations;
private readonly onConstruct;
private readonly onDispose;
private readonly injector;
constructor(options?: {
injector?: IInjector;
parent?: IContainer;
tags?: Tag[];
onConstruct?: (instance: Instance, scope: IContainer) => void;
onDispose?: (scope: IContainer) => void;
});
register(key: DependencyKey, provider: IProvider, { aliases }?: RegisterOptions): this;
addRegistration(registration: IRegistration): this;
getRegistrations(): IRegistration[];
resolveByClass<T>(token: constructor<T>, { args }?: {
args?: unknown[];
}): T;
resolveOne<T>(keyOrAlias: constructor<T> | DependencyKey, options?: ResolveOneOptions): T;
resolveOneByKey<T>(keyOrAlias: DependencyKey, { args, child, lazy }?: ResolveOneOptions): T;
resolveOneByAlias<T>(keyOrAlias: DependencyKey, { args, child, lazy }?: ResolveOneOptions): T;
resolveMany<T>(alias: DependencyKey, { args, child, lazy, excludedKeys }?: ResolveManyOptions): T[];
createScope({ tags }?: CreateScopeOptions): IContainer;
getScopes(): IContainer[];
removeScope(child: IContainer): void;
useModule(module: IContainerModule): this;
getParent(): IContainer;
getInstances(): Instance<unknown>[];
hasTag(tag: Tag): boolean;
dispose(): void;
/**
* @private
*/
applyRegistrationsFrom(source: Container): void;
private validateContainer;
}