mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
feat(core): allow overriding abort on error for select method
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { ShutdownSignal } from '../enums/shutdown-signal.enum';
|
||||
import { LoggerService, LogLevel } from '../services/logger.service';
|
||||
import { DynamicModule } from './modules';
|
||||
import { NestApplicationContextOptions } from './nest-application-context-options.interface';
|
||||
import { Type } from './type.interface';
|
||||
|
||||
export type SelectOptions = Pick<NestApplicationContextOptions, 'abortOnError'>;
|
||||
|
||||
export interface GetOrResolveOptions {
|
||||
/**
|
||||
* If enabled, lookup will only be performed in the host module.
|
||||
@@ -27,7 +30,10 @@ export interface INestApplicationContext {
|
||||
* Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.
|
||||
* @returns {INestApplicationContext}
|
||||
*/
|
||||
select<T>(module: Type<T> | DynamicModule): INestApplicationContext;
|
||||
select<T>(
|
||||
module: Type<T> | DynamicModule,
|
||||
options?: SelectOptions,
|
||||
): INestApplicationContext;
|
||||
|
||||
/**
|
||||
* Retrieves an instance of either injectable or controller, otherwise, throws exception.
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
Abstract,
|
||||
DynamicModule,
|
||||
GetOrResolveOptions,
|
||||
SelectOptions,
|
||||
Type,
|
||||
} from '@nestjs/common/interfaces';
|
||||
import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
|
||||
@@ -87,6 +88,7 @@ export class NestApplicationContext<
|
||||
*/
|
||||
public select<T>(
|
||||
moduleType: Type<T> | DynamicModule,
|
||||
selectOptions?: SelectOptions,
|
||||
): INestApplicationContext {
|
||||
const modulesContainer = this.container.getModules();
|
||||
const contextModuleCtor = this.contextModule.metatype;
|
||||
@@ -101,9 +103,18 @@ export class NestApplicationContext<
|
||||
if (!selectedModule) {
|
||||
throw new UnknownModuleException(type.name);
|
||||
}
|
||||
|
||||
const options =
|
||||
typeof selectOptions?.abortOnError !== 'undefined'
|
||||
? {
|
||||
...this.appOptions,
|
||||
...selectOptions,
|
||||
}
|
||||
: this.appOptions;
|
||||
|
||||
return new NestApplicationContext(
|
||||
this.container,
|
||||
this.appOptions,
|
||||
options,
|
||||
selectedModule,
|
||||
scope,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user