@micro.ts/core
Version:
Microservice framework with Typescript
62 lines (61 loc) • 2.03 kB
TypeScript
import { RegistryKey, DiRegistry } from './DiRegistry';
/**
* Container Module is a scoped dependency resolver and container,
* The module is used to manage the main container dependencies,
* also the request scoped dependencies
* A new module is created when calling Container.newModule
* using the current container module as the parent of the new module
* therefore treating the newly created module as request scoped
*/
export declare class ContainerModule {
private registry;
private parent?;
/**
* If a parent is provided, this module is a scoped module,
* meaning for singleton scoped dependencies it will fall back to the parent module
* @param registyr
* @param parent
*/
constructor(registry?: DiRegistry, parent?: ContainerModule | undefined);
/**
* Key value to store the resolved dependencies if they match the module scope
*/
private instances;
/**
* Return true only if it has a parent
*/
private get isScoped();
/**
* Construct an object with its constructor,
* using the information it has from the constructor metadata
* If not in transient scope store the created value
* @param ctor
* @param keyMetadata
*/
private buildValue;
/**
* Resolve with the resolver and store the value if not transient scoped
* @param key
* @param resolveItem
*/
private resolve;
/**
* Return true if this module is scoped and the required scope is singleton scope
* Throws error if this module is not scoped and the required scope is request scoped
* @param scope
*/
private useParentScope;
/**
* Set an arbitrary value for the given key
* @param key
* @param value
*/
set<T>(key: RegistryKey<T>, value: T): void;
/**
* Try and resolve the value
* Might return undefined if it doesn't find
* the stored key and/or cannot construct the value
* @param key
*/
get<T = any>(key: RegistryKey): T;
}