UNPKG

ts-ioc-container

Version:

Fast, lightweight TypeScript dependency injection container with a clean API, scoped lifecycles, decorators, tokens, hooks, lazy injection, customizable providers, and no global container objects.

15 lines (14 loc) 1.05 kB
import { type IHookContext } from './HookContext'; import type { IContainer } from '../container/IContainer'; import { type constructor } from '../utils/basic'; import { ProviderOptions } from '../provider/IProvider'; export type InjectFn<T = unknown> = (s: IContainer, options: ProviderOptions) => T; 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 type HooksOfClass = Map<string, (HookFn | constructor<HookClass>)[]>; export declare const toHookFn: <C extends IHookContext>(execute: HookFn<C> | constructor<HookClass<C>>) => HookFn<C>; export declare function getHooks(target: object, key: string | symbol): HooksOfClass; export declare function hasHooks(target: object, key: string | symbol): boolean; export declare const hook: (key: string | symbol, ...fns: (HookFn | constructor<HookClass>)[]) => (target: object, propertyKey: string | symbol) => void;