@jems/di
Version:
An implementation of IoC pattern based on dependency injection that allows you to granulate and decouple your libraries or applications. Wrote using SOLID principles and a variety OOP patterns implementations.
168 lines (167 loc) • 7.92 kB
TypeScript
import { Module } from './module';
import { DependencyMetadata } from './dependencyMetadata';
import { Kernel } from './kernel';
import { KernelConfiguration } from './kernelConfiguration';
import { ResolutionContext } from './resolutionContext';
import { ResolutionOption } from './resolutionOption';
import { ContainerizedKernel } from './containerizedKernel';
import { ToSyntax } from './fluent-syntaxes/toSyntax';
import { AliasMetadata } from './aliasMetadata';
/**
* Represents a kernel that manage the type registration, instance activation and servicing strategies.
* @private
*/
export declare class BuildInKernel implements Kernel {
private _defaultContainerAlias;
private _containers;
private _currentContainer;
private _kernelConfiguration;
private _aliasMetadataMap;
/**
* Instance a new kernel.
*/
constructor();
/**
* Returns the configuration of the kernel.
*/
readonly configuration: KernelConfiguration;
/**
* Get the alias metadata map to configure aliases behavior.
*/
readonly aliasMetadataMap: {
[alias: string]: AliasMetadata;
};
/**
* Load thegiven modules into the kernel.
* @param {Module[]} modules Represents the modules that will be loaded in the kernel.
*/
loadModules(modules: Module[]): void;
/**
* Load the given modules into the kernel asynchronous.
* @param {Module[]} modules Represents the modules that will be loaded in the kernel.
* @returns {Promise<void>} A Promise that load the modules.
*/
loadModulesAsync(modules: Module[]): Promise<void>;
/**
* Return a containerized resolution syntax that allow perform resolution with an exiting container.
* @param alias Represents the alias of the container to look for.
* @return {ContainerizedKernel} The containerized resolution systax.
*/
usingContainer(alias: string): ContainerizedKernel;
/**
* Return a containerized resolution syntax that allow perform resolution with the defautl container.
* @return {ContainerizedKernel} The containerized resolution systax.
*/
usingDefaultContainer(): ContainerizedKernel;
/**
* Creates and returns a container with the given alias.
* @param {string} alias Represents the alias of the container.
* @param {string[]} supports Represents the aliases of the supports containers.
* @return {Container} The created container.
*/
createContainer(alias: string, supports?: string[]): void;
/**
* Returns a boolean value specifying if the given alias can be resolved.
* @param {string} alias Represents the alias to look for.
* @return {boolean} True if the given alias can be resolved.
*/
canResolve(alias: string): boolean;
/**
* Return an resolved instance using the given reference that could be a class, function or alias.
* @param {{ new ():any } | Function | string} reference Represents the reference that must be resolved, it could be a class, function or alias.
* @param {ResolutionOption} resolutionOption Represents the options to resolve the the reference.
* @return {any} The resolved object.
*/
resolve(reference: {
new (): any;
} | Function | string, resolutionOption?: ResolutionOption): any;
/**
* Return a promise that provided a resolved instance using the given reference that could be a class, function or alias.
* @param {{ new ():any } | Function | string} reference Represents the reference that must be resolved, it could be a class, function or alias.
* @param {ResolutionOption} resolutionOption Represents the options to resolve the the reference.
* @return {Promise<any>} A promise that resolve the objects.
*/
resolveAsync(reference: {
new (): any;
} | Function | string, resolutionOption?: ResolutionOption): Promise<any>;
/**
* Return an resolved instance using the given reference that could be a class, function or alias.
* @param {{ new ():any } | Function | string} reference Represents the reference that must be resolved, it could be a class, function or alias.
* @param {ResolutionContext} resolutionContext Represents the context of the resolution.
* @return {any} The resolved object.
*/
resolveWithContext(reference: {
new (): any;
} | Function | string, resolutionContext: ResolutionContext): any;
/**
* Return a promise that provided a resolved instance using the given reference that could be a class, function or alias.
* @param {{ new ():any } | Function | string} reference Represents the reference that must be resolved, it could be a class, function or alias.
* @param {ResolutionContext} resolutionContext Represents the context of the resolution.
* @return {Promise<any>} A promise that resolve the objects.
*/
resolveWithContextAsync(reference: {
new (): any;
} | Function | string, resolutionContext: ResolutionContext): Promise<any>;
/**
* Return an alias bind fluent syntax that allow register dependencies metadata in a fluent api syntax.
* @param {string} alias Represents the alias to look for.
* @returns {ToSyntax} A fluent bind.
*/
bind(alias: string): ToSyntax;
/**
* Unbind all dependencies metadata with the given alias from the container.
* @param {string} alias Represents the alias to look for.
*/
unbindWithAlias(alias: string): void;
/**
* Unbind the dependency metadata with the given identifier from the container.
* @param {string} identifier Represents the identifier to look for.
*/
unbindWithIdentifier(identifier: string): void;
/**
* Returns the registered dependency metadata with the given alias and identifier.
* @param {string} identifier Represents the identifier to look for.
* @returns {string} Return dependency metadata with the given identifier.
*/
getDependencyMetadataWithIdentifier(identifier: string): DependencyMetadata;
/**
* Returns the generated identifier and register the given metadata with the given alias for his future activation.
* @param {string} alias Represents the alias.
* @param {DependencyMetadata} dependencyMetadata Represents the dependency metadata.
* @returns {string} Returns the dependency metadata generated identifier.
*/
registerDependencyMetadata(alias: string, dependencyMetadata: DependencyMetadata): string;
/**
* Unregister all registered dependencies metadata with the given alias.
* @param {string} alias Represents the alias to to look for.
*/
unregisterDependenciesMetadataWithAlias(alias: string): void;
/**
* Unregister the dependency metadata with the given alias and identifier.
* @param {string} identifier Represents the identifier to look for.
*/
unregisterDependencyMetadataWithIdentifier(identifier: string): void;
/**
* Removes the container with the given alias.
* @param {string} alias Represents the alias of the container.
*/
removeContainer(alias: string): void;
/**
* Returns a boolean value specifying if the kernel has a container with the given alias.
* @param {string} alias Represents the alias of the container.
* @returns {boolean} True if the kernel has the container.
*/
hasContainer(alias: string): boolean;
/**
* Dispose and release all the objects and containers in the kernel.
*/
dispose(): void;
/**
* Dispose and release all the objects and containers in the kernel asynchronous.
* @returns {Promise<void>} A promise that dispose the kernel.
*/
disposeAsync(): Promise<void>;
private createNewContainer(alias, supports);
private getContainerizedKernel(container);
private validateCiclycDependency(stack, supports);
}