ts-ioc-container
Version:
Typescript IoC container
19 lines (18 loc) • 1.2 kB
TypeScript
import type { DependencyKey, IContainer, IContainerModule } from '../container/IContainer';
import type { constructor, MapFn } from '../utils';
import type { IProvider } from '../provider/IProvider';
import type { DepKey } from '../DepKey';
import { ProviderPipe } from '../provider/ProviderPipe';
export type ScopePredicate = (s: IContainer, prev?: boolean) => boolean;
export interface IRegistration<T = any> extends IContainerModule {
when(...predicates: ScopePredicate[]): this;
bindToKey(key: DependencyKey): this;
pipe(...mappers: (MapFn<IProvider<T>> | ProviderPipe<T>)[]): this;
bindToAlias(alias: DependencyKey): this;
}
export type ReturnTypeOfRegistration<T> = T extends IRegistration<infer R> ? R : never;
export declare const scope: (...predicates: ScopePredicate[]) => MapFn<IRegistration>;
export declare const getTransformers: (Target: constructor<unknown>) => MapFn<IRegistration<any>>[];
export declare const register: (...mappers: Array<MapFn<IRegistration> | ProviderPipe>) => ClassDecorator;
export declare const asAlias: (target: DependencyKey | DepKey<any>) => MapFn<IRegistration>;
export declare const asKey: (key: DependencyKey) => MapFn<IRegistration>;