vulcain-corejs
Version:
Vulcain micro-service framework
144 lines (143 loc) • 4.41 kB
TypeScript
import 'reflect-metadata';
import { Scope } from './scope';
import { IContainer, BusUsage } from '../di/resolvers';
import { LifeTime } from './annotations';
import { RequestContext } from './../servers/requestContext';
/**
* Component container for dependency injection
*
* @export
* @class Container
* @implements {IContainer}
*/
export declare class Container implements IContainer {
private parent;
private resolvers;
scope: Scope;
/**
* Creates an instance of Container.
*
* @param {IContainer} [parent]
* @param {RequestContext} [requestContext]
*
* @memberOf Container
*/
constructor(parent?: IContainer, requestContext?: RequestContext);
/**
* used by test
*
* @protected
* @param {RequestContext} requestContext
*
* @memberOf Container
*/
protected setRequestContext(requestContext: RequestContext): void;
dispose(): void;
/**
* Inject all components from files of the specified folder.
* Files are loaded recursively
*
* @param {string} folder path relative to the current directory
* @returns the current container
*/
injectFrom(path: string): this;
/**
*
*
* @param {string} address rabbitmq server address (only host name and optional port)
* @param {any} [usage=BusUsage.all]
*/
useRabbitBusAdapter(address?: string, usage?: BusUsage): void;
/**
* Use mongo provider
*
* @param {string} mongo server address (only host name or list of host names)
* @param {any} [mongoOptions] Mongodb options
*/
useMongoProvider(address?: string, mongoOptions?: any): void;
/**
* Use a memory provider by default
*
* @param {string} [folder] Data can be persisted on disk (on every change)
*/
useMemoryProvider(folder?: string): void;
/**
* Register a instance of a component
*
* @param name
* @param fn
* @returns {Container}
*/
injectInstance(fn: any, name: string): this;
/**
* Register a component as a singleton. It will be created on first use.
*
* @param fn
* @param args
*/
injectSingleton(fn: any, ...args: any[]): any;
injectSingleton(fn: any, name?: string, ...args: any[]): any;
/**
* A new component are always created
*
* @param fn Component constructor
* @param args
*/
injectTransient(fn: any, ...args: any[]): any;
injectTransient(fn: any, name?: string, ...args: any[]): any;
/**
* Scoped by request. Component are initialized with the current requestContext
*
* @param fn
* @param args
*/
injectScoped(fn: any, ...args: any[]): any;
injectScoped(fn: any, name?: string, ...args: any[]): any;
/**
* Helper for injecting component
*
* @param {string} name Component name
* @param {any} fn Component constructor
* @param {LifeTime} lifeTime Component lifetime
*
* @memberOf Container
*/
inject(name: string, fn: any, lifeTime: LifeTime): void;
/**
*
* Instanciate a component and resolve all of its dependencies
* @param fn Component constructor
* @param args List of optional arguments
* @returns {null}
*/
resolve(fn: any, ...args: any[]): any;
private _resolve(parentContainer, resolver, name?, optional?);
private findResolver(name);
/**
* Get a component by name.
* Throw an exception if the component doesn't exist
* @template T
* @param {string} component name
* @param {boolean} [optional] if true no exception are raised if the component doesn't exist
* @param {LifeTime} [assertLifeTime] If provide check if the registered component has the expected {LifeTime}
* @returns A component
*/
get<T>(name: string, optional?: boolean, assertLifeTime?: LifeTime): T;
}
/**
* Default container for test
*
* @export
* @class TestContainer
* @extends {Container}
*/
export declare class TestContainer extends Container {
domainName: string;
/**
* Creates an instance of TestContainer.
*
* @param {string} domainName Domain name
* @param {(container: IContainer) => void} [addDefaultServices] Additional default services to register
*/
constructor(domainName: string, addDefaultServices?: (container: IContainer) => void);
}