dependency-injection-cat
Version:
DI Cat is a truly clean DI-container, which allows you not to pollute your business logic with decorators from DI/IOC libraries!
60 lines (58 loc) • 2.38 kB
TypeScript
export interface IDIContext<TBeans> {
getBeans(): TBeans;
getBean<TBean extends keyof TBeans>(beanName: TBean): TBeans[TBean];
}
export interface IInitContextProps {
name: string;
key?: any;
}
export interface IInitContextPropsWithConfig<TConfig> extends IInitContextProps {
config: TConfig;
}
export declare type TBeanName = string;
declare class Container {
/**
* TBeans should be a plain interface without extending
*/
initContext<TBeans>(props: IInitContextProps): IDIContext<TBeans>;
initContext<TBeans, TConfig>(props: IInitContextPropsWithConfig<TConfig>): IDIContext<TBeans>;
/**
* TBeans should be a plain interface without extending
*/
getOrInitContext<TBeans>(props: IInitContextProps): IDIContext<TBeans>;
getOrInitContext<TBeans, TConfig>(props: IInitContextPropsWithConfig<TConfig>): IDIContext<TBeans>;
/**
* TBeans should be a plain interface without extending
*/
getContext<TBeans extends Record<TBeanName, any>>(props: IInitContextProps): IDIContext<TBeans>;
clearContext(props: IInitContextProps): void;
private static throwInitializationError;
}
export declare const container: Container;
/**
* TBeans should be a plain interface without extending
*/
export declare abstract class CatContext<TBeans, TConfig = null> {
protected constructor();
get config(): TConfig;
}
export declare abstract class GlobalCatContext {
protected constructor();
}
export declare type TClassConstructor<T> = new (...args: any[]) => T;
export declare type TBeanScope = "prototype" | "singleton";
export interface IBeanConfig {
scope?: TBeanScope;
}
export declare type ConfigurableMethodBean = (beanConfig: IBeanConfig) => PropertyDecorator;
export declare type PropertyBean = <T>(clazz: TClassConstructor<T>, beanConfig?: IBeanConfig) => T;
export declare type TBean = PropertyDecorator & ConfigurableMethodBean & PropertyBean;
export declare const Bean: TBean;
export declare const Qualifier: <T extends string>(beanName: T extends "" ? never : T) => ParameterDecorator;
export declare type TPostConstruct = PropertyDecorator & MethodDecorator;
export declare const PostConstruct: TPostConstruct;
export declare type TBeforeDestruct = PropertyDecorator & MethodDecorator;
export declare const BeforeDestruct: TBeforeDestruct;
export declare type TEmbeddedBean = PropertyDecorator;
export declare const EmbeddedBean: TEmbeddedBean;
export {};