@booster-ts/core
Version:
Core Booster DI Library
98 lines (97 loc) • 2.61 kB
TypeScript
declare type IType<T> = new (...args: Array<any>) => T;
interface IContainer {
name: string;
class: any;
data?: any;
target: IType<any>;
}
/**
* booster
* @description Decorator to retreive Classes
* @param data info to attach to the Class
*/
export declare const booster: (data?: any) => (target: IType<any>) => void;
/**
* Injector
* @description Container to Store and Retreive Classes
*/
export declare class Injector {
private container;
/**
* register
* @description Register a Class with a custom name
* @param className Name you want the class to have
* @param target Class to register
* @example
* ```
* @booster()
* class Example {
* }
*
* Inject.register('CustomExample', Example);
* ```
*/
register<T>(className: string, target: IType<T>): T;
/**
* inject
* @description Retrive class with dependencies injected
* @param target Class to inject
* @example
* ```
* @booster()
* class Greeter {
* public hello() {
* return "Hello";
* }
* }
*
* @booster()
* class Human {
* constructor(
* greet: Greeter
* ) { }
*
* public hello(): string {
* return greet.hello();
* }
* }
*
* const example = Inject.inject(Example);
* example.hello() // Returns "Hello"
* ```
*/
inject<T>(target: IType<T>): T;
/**
* getByKey
* @description Gets all class with a specific key attached as metadata
* @param keyName Key to find on Target
*/
getByKey<T>(keyName: string): Array<T>;
/**
* getByValue
* @description Gets all class with a specific value to the key attached as metadata
* @param keyName Key to find on Target
* @param value to find on key
*/
getByValue<T>(keyName: string, value: any): Array<T>;
/**
* getContainerByKey
* @description Returns Container with certain key
* @param keyName to find on target
*/
getContainerByKey(keyName: string): Array<IContainer>;
/**
* getContainerByValue
* @description Gets all class with a specific value to the key attached as metadata
* @param keyName Key to find on Target
* @param value to find on key
*/
getContainerByValue(keyName: string, value: any): Array<IContainer>;
/**
* resolve
* @description Resolves dependencies and retruns injected Class
* @param target Class
*/
private resolve;
}
export {};