inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
74 lines (73 loc) • 3.28 kB
TypeScript
import Config from '../config/ConfigProvider';
import { Logger } from '../log/LogManager';
import { Lifecycle } from './Lifecycle';
import { ObjectDefinition } from './objectdefinition/ObjectDefinition';
import { ObjectDefinitionInspector } from './ObjectDefinitionInspector';
/**
* A context used by IoC to register and request objects from.
* This is the main class for the inversion of control framework. It serves as a registry where you can
* add {ObjectDefinition}s and request instances from them.
*/
export interface ContextOptions {
logger?: Logger;
config?: Config;
}
export declare class Context extends Lifecycle {
private objectDefinitionInspector;
private startedObjects;
private objectDefinitions;
private parentContext;
private config;
private objectGroups;
constructor(name: string, parentContext?: Context, options?: ContextOptions);
lcStart(): Promise<void>;
lcStop(): Promise<void>;
protected doStart(): Promise<void>;
protected doStop(): Promise<any>;
clone(name: any): Context;
importContext(otherContext: any, overwrite?: boolean): void;
addObjectDefinitionInspector(inspector: ObjectDefinitionInspector): void;
registerDefinition(objectDefinition: ObjectDefinition<any>, overwrite?: boolean): void;
registerSingletons(...singletons: any[]): void;
registerSingletonsInDir(dir: any): void;
static requireFilesInDir(dir: any): void;
/**
* Walks a directory recursively and returns an array with all the files
*
* @private
* @param dir The directory to walk through
* @param filelist The carried-over list of files
* @return {Array} The list of files in this directory and subdirs
*/
static walkDirSync(dir: any, filelist?: any[]): any[];
/**
* Get an element from the configuration.
* Can be both a leaf of the configuration, or an intermediate path. In the latter case it will return
* an object with all the configs under that path.
* It will throw an exception if the key doesn't exist.
*
* @param {string} key The key of the config we want
* @param {*} defaultValue A default value to use if the key doesn't exist
* @return {*} The requested configuration
* @throws {Error} If the given key doesn't exist and a default value is not provided
* @see {@link Context.hasConfig}
*/
getConfig(key: string, defaultValue?: any): any;
/**
* Indicates whether a given key exists in the configuration
* @param key
* @return {*}
*/
hasConfig(key: string): boolean;
addObjectNameToGroup(groupName: string, objectName: string): void;
getGroupObjectNames(groupName: string): string[];
getObjectByName(beanName: any): Promise<any>;
getObjectByType(className: any): Promise<any>;
getObjectsByType(className: any): Promise<any[]>;
getObjectsByGroup(groupName: any): Promise<any[]>;
getDefinitionByName(objectName: any): ObjectDefinition<any>;
getDefinitionByType(className: any): ObjectDefinition<any>;
getDefinitionsByType(className: any, failOnMissing?: boolean): Array<ObjectDefinition<any>>;
getDefinitionsByGroup(groupName: any): Array<ObjectDefinition<any>>;
applyObjectDefinitionModifiers(): void;
}