@blynx/inject
Version:
Dependency injector for javascript
67 lines (66 loc) • 1.94 kB
TypeScript
/**
* A type that we can instantiate. Returns T
*/
export declare type NewableType<T> = {
new (...args: any[]): T;
};
export declare class InjectProvider {
private static _instance;
private injectables;
private readonly SYMBOL_ID;
private constructor();
/**
* Instance of InjectProvider
*
* @readonly
* @static
* @type {InjectProvider}
* @memberOf InjectProvider
*/
static readonly Instance: InjectProvider;
/**
* Check a class for a symbol id
*
* @param {NewableType<any>} instanceType Class to check for Id
* @returns {boolean}
*/
hasId(instanceType: NewableType<any>): boolean;
/**
* Get a classes symbol id
*
* @param {NewableType<any>} instanceType Class to get symbol id for
* @returns {Symbol} Symbol id of the class
*
* @memberOf InjectProvider
*/
getId(instanceType: NewableType<any>): any;
/**
* Set the name a of a newable type
*
* @param {string} namespace Namespace to prepend
* @param {NewableType<any>} instanceType Newable instance type
*
* @memberOf InjectProvider
*/
setName(namespace: string, instanceType: NewableType<any>): void;
/**
* Get an instance of an injectable
*
* @template T Type of instance
* @param {NewableType<any>} instanceType Instance type to get
* @returns Instance of injectable or null
*
* @memberOf InjectProvider
*/
get<T>(instanceType: NewableType<T>): T | null;
/**
* Register an injectable
*
* @template T Type of injectable
* @param {NewableType<T>} instanceType Instance type to create
* @param {Symbol?} key Unique ID for instance. Use when defining a new constructor for an existing injectable
*
* @memberOf InjectProvider
*/
register<T extends Function>(instanceType: NewableType<T>, key?: any): void;
}