inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
88 lines (87 loc) • 3.87 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;
shutdownTimer?: number;
}
export declare class Context extends Lifecycle {
private objectDefinitionInspector;
private startedObjects;
private objectDefinitions;
private parentContext;
private config;
private objectGroups;
private shutdownTimer;
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(patterns: any, options: 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[];
/**
* find matching files based on the given path or glob
*
* @param {string} patterns - glob pattern(s) or relative path
* @param {boolean} [isGlob] - pass true to treat the path as a glob
* @param {Object} [globOptions] - options to pass to globby
* @returns {Array<string>} files
*/
static findMatchingFiles(patterns: string | Array<string>, { isGlob, globOptions }: {
isGlob: boolean;
globOptions: Object;
}): Array<string>;
/**
* 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: string): Promise<any>;
getObjectByType(className: string): Promise<any>;
getObjectsByType(className: string): Promise<any[]>;
getObjectsByGroup(groupName: string): Promise<any[]>;
getDefinitionByName(objectName: string): ObjectDefinition<any>;
getDefinitionByType(className: string): ObjectDefinition<any>;
getDefinitionsByType(className: string, failOnMissing?: boolean): Array<ObjectDefinition<any>>;
getDefinitionsByGroup(groupName: string): Array<ObjectDefinition<any>>;
applyObjectDefinitionModifiers(): void;
}