@micro.ts/core
Version:
Microservice framework with Typescript
65 lines (64 loc) • 1.95 kB
TypeScript
import { Class } from '../server';
import { ServiceOptions } from './types';
import { ServiceScope } from './types/DiOptionsTypes';
import { ContainerModule } from './ContainerModule';
export declare class RegistryToken<T> {
name?: string | undefined;
constructor(name?: string | undefined);
}
export declare type RegistryKey<T = any> = Class<T> | RegistryToken<T> | string;
export declare type ResolverFunction<T = any> = ((module: ContainerModule) => T) | (() => T);
export declare type ResolverRegistryItem<T = any> = {
resolver: ResolverFunction<T>;
scope: ServiceScope;
};
export declare class DiRegistry {
/**
* Store service metadata
*/
private serviceOptions;
/**
* Store resolvers metadata and resolver functions
*/
private resolvers;
/**
* Verify for circular dependencies
* @param key
* @param visited
*/
private verify;
/**
* Bind a key to a constructor function
* @param key
* @param options
*/
bind(key: RegistryKey, options: ServiceOptions): void;
/**
* Bind a key to a given resolver function
* @param key
* @param resolver
* @param scope
*/
bindResolver<T>(key: RegistryKey<T | string>, resolver: ResolverFunction<T>, scope?: ServiceScope): void;
/**
* Check if a resolver exists for a given key
* @param key
*/
hasResolver<T>(key: RegistryKey<T>): boolean;
/**
* Get stored metadata for a given key
* @param key
*/
getMetadata<T>(key: RegistryKey<T>): ServiceOptions | undefined;
/**
* Return resolver information and resolving function
* @param key
*/
getResolver<T>(key: RegistryKey<T>): ResolverRegistryItem<T>;
/**
* Default metadata if they are not specified
* @param key
*/
initializeMetadata<T>(key: RegistryKey<T | string>): ServiceOptions;
}
export declare const ContainerRegistry: DiRegistry;