mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
Merge branch 'master' of https://github.com/peawyoyoyin/nest into peawyoyoyin-master
This commit is contained in:
@@ -50,7 +50,7 @@ export async function callBeforeAppShutdownHook(
|
||||
module: Module,
|
||||
signal?: string,
|
||||
): Promise<void> {
|
||||
const providers = [...module.providers];
|
||||
const providers = [...module.getNonAliasProviders()];
|
||||
const [_, { instance: moduleClassInstance }] = providers.shift();
|
||||
const instances = [...module.controllers, ...providers];
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ function callOperator(instances: InstanceWrapper[]): Promise<any>[] {
|
||||
* @param module The module which will be initialized
|
||||
*/
|
||||
export async function callModuleBootstrapHook(module: Module): Promise<any> {
|
||||
const providers = [...module.providers];
|
||||
const providers = [...module.getNonAliasProviders()];
|
||||
// Module (class) instance is the first element of the providers array
|
||||
// Lifecycle hook has to be called once all classes are properly initialized
|
||||
const [_, { instance: moduleClassInstance }] = providers.shift();
|
||||
|
||||
@@ -47,7 +47,7 @@ export async function callAppShutdownHook(
|
||||
module: Module,
|
||||
signal?: string,
|
||||
): Promise<any> {
|
||||
const providers = [...module.providers];
|
||||
const providers = [...module.getNonAliasProviders()];
|
||||
// Module (class) instance is the first element of the providers array
|
||||
// Lifecycle hook has to be called once all classes are properly initialized
|
||||
const [_, { instance: moduleClassInstance }] = providers.shift();
|
||||
|
||||
@@ -39,7 +39,7 @@ function callOperator(instances: InstanceWrapper[]): Promise<any>[] {
|
||||
* @param module The module which will be initialized
|
||||
*/
|
||||
export async function callModuleDestroyHook(module: Module): Promise<any> {
|
||||
const providers = [...module.providers];
|
||||
const providers = [...module.getNonAliasProviders()];
|
||||
// Module (class) instance is the first element of the providers array
|
||||
// Lifecycle hook has to be called once all classes are properly destroyed
|
||||
const [_, { instance: moduleClassInstance }] = providers.shift();
|
||||
|
||||
@@ -35,7 +35,7 @@ function callOperator(instances: InstanceWrapper[]): Promise<any>[] {
|
||||
* @param module The module which will be initialized
|
||||
*/
|
||||
export async function callModuleInitHook(module: Module): Promise<void> {
|
||||
const providers = [...module.providers];
|
||||
const providers = [...module.getNonAliasProviders()];
|
||||
// Module (class) instance is the first element of the providers array
|
||||
// Lifecycle hook has to be called once all classes are properly initialized
|
||||
const [_, { instance: moduleClassInstance }] = providers.shift();
|
||||
|
||||
@@ -42,6 +42,8 @@ export class InstanceWrapper<T = any> {
|
||||
public inject?: (string | symbol | Function | Type<any>)[];
|
||||
public forwardRef?: boolean;
|
||||
|
||||
public isAlias: Boolean = false;
|
||||
|
||||
private readonly values = new WeakMap<ContextId, InstancePerContext<T>>();
|
||||
private readonly [INSTANCE_METADATA_SYMBOL]: InstanceMetadataStore = {};
|
||||
private readonly [INSTANCE_ID_SYMBOL]: string;
|
||||
|
||||
@@ -351,6 +351,7 @@ export class Module {
|
||||
isResolved: false,
|
||||
inject: [useExisting],
|
||||
host: this,
|
||||
isAlias: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -472,6 +473,18 @@ export class Module {
|
||||
return this._providers.get(name) as InstanceWrapper<T>;
|
||||
}
|
||||
|
||||
public getNonAliasProviders(): Map<string, InstanceWrapper<Injectable>> {
|
||||
const result = new Map<string, InstanceWrapper<Injectable>>();
|
||||
|
||||
this._providers.forEach((wrapper, key) => {
|
||||
if (!wrapper.isAlias) {
|
||||
result.set(key, wrapper);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public createModuleReferenceType(): any {
|
||||
const self = this;
|
||||
return class extends ModuleRef {
|
||||
|
||||
@@ -262,6 +262,7 @@ describe('Module', () => {
|
||||
instance: null,
|
||||
inject: [provider.useExisting as any],
|
||||
isResolved: false,
|
||||
isAlias: true,
|
||||
}),
|
||||
),
|
||||
).to.be.true;
|
||||
|
||||
Reference in New Issue
Block a user