ts-ioc-container
Version:
Typescript IoC container
30 lines (29 loc) • 1.97 kB
TypeScript
import { type IContainer } from '../container/IContainer';
import { type CreateHookContext, createHookContext, type IHookContext, type InjectFn } from './HookContext';
import { type constructor } from '../utils';
import { type IInjectFnResolver } from '../injector/IInjector';
export type HookFn<T extends IHookContext = IHookContext> = (context: T) => void | Promise<void>;
export interface HookClass<T extends IHookContext = IHookContext> {
execute(context: Omit<T, 'scope'>): void | Promise<void>;
}
export declare const toHookFn: <C extends IHookContext>(execute: HookFn<C> | constructor<HookClass<C>>) => HookFn<C>;
type HooksOfClass = Map<string, (HookFn | constructor<HookClass>)[]>;
export declare const hook: (key: string | symbol, ...fns: (HookFn | constructor<HookClass>)[]) => (target: object, propertyKey: string | symbol) => void;
export declare function getHooks(target: object, key: string | symbol): HooksOfClass;
export declare function hasHooks(target: object, key: string | symbol): boolean;
export declare const runHooks: (target: object, key: string | symbol, { scope, createContext, predicate, }: {
scope: IContainer;
createContext?: CreateHookContext;
predicate?: (methodName: string) => boolean;
}) => void;
export declare const runHooksAsync: (target: object, key: string | symbol, { scope, createContext, predicate, }: {
scope: IContainer;
createContext?: typeof createHookContext;
predicate?: (methodName: string) => boolean;
}) => Promise<void[]>;
export declare const injectProp: (fn: InjectFn | IInjectFnResolver<unknown>) => HookFn;
export declare const onConstruct: (fn: HookFn) => (target: object, propertyKey: string | symbol) => void;
export declare const runOnConstructHooks: (target: object, scope: IContainer) => void;
export declare const onDispose: (target: object, propertyKey: string | symbol) => void;
export declare const runOnDisposeHooks: (target: object, scope: IContainer) => void;
export {};