@nestjs/common#INestApplicationContext TypeScript Examples
The following examples show how to use
@nestjs/common#INestApplicationContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: nest-factory.d.ts From nest-jaeger with MIT License | 6 votes |
/**
* Creates an instance of NestApplicationContext.
*
* @param module Entry (root) application module class
* @param options Optional Nest application configuration
*
* @returns A promise that, when resolved,
* contains a reference to the NestApplicationContext instance.
*/
createApplicationContext(module: any, options?: NestApplicationContextOptions): Promise<INestApplicationContext>;
Example #2
Source File: test-environment.ts From relate with GNU General Public License v3.0 | 6 votes |
constructor(
public readonly filename: string,
public readonly app: INestApplicationContext,
public readonly systemProvider: SystemProvider,
public readonly environment: LocalEnvironment,
) {
if (process.env.NODE_ENV !== 'test') {
throw new NotSupportedError('Cannot use TestEnvironment outside of testing environment');
}
}
Example #3
Source File: nest-application-context.d.ts From nest-jaeger with MIT License | 5 votes |
select<T>(moduleType: Type<T>): INestApplicationContext;
Example #4
Source File: base.command.ts From relate with GNU General Public License v3.0 | 5 votes |
run(): Promise<INestApplicationContext> {
const parsed = this.parse(this.commandClass);
const utils = {
debug: this.debug,
error: this.error,
log: this.log,
exit: this.exit,
warn: this.warn,
};
const options: {logger?: false} = IS_DEVELOPMENT_ENV ? {} : {logger: false};
const {flags} = parsed;
const cliExtensions = loadExtensionsFor(EXTENSION_TYPES.CLI, flags.environment);
const systemConfig: ISystemModuleConfig = {defaultEnvironmentNameOrId: flags.environment};
registerHookListener(HOOK_EVENTS.DEBUG, (msg) => this.debug(msg));
return NestFactory.createApplicationContext(
{
imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [() => systemConfig],
}),
SystemModule.register(systemConfig),
...cliExtensions,
],
module: this.commandModule,
providers: [
{
provide: 'PARSED_PROVIDER',
useValue: parsed,
},
{
provide: 'UTILS_PROVIDER',
useValue: utils,
},
],
},
options,
).catch((err) => {
// When exiting with Ctrl-C an undefined error is thrown, oclif is
// supposed to hide it, but it still shows for some reason.
if (!err) {
this.exit(0);
}
if (IS_DEVELOPMENT_ENV || IS_TEST_ENV) {
throw err;
}
if (!('oclif' in err)) {
// If passed a generic error object, wrap it in CLIError to show the full stack trace
// even when not in debug mode. If it's passed a message it will display
// the error message nicely to the user, and if debug mode is enabled
// it will display the stack trace too.
const cliError = new CLIError(err.message);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
cliError.name = err.name;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
cliError.stack = err.stack;
throw cliError;
} else {
throw err;
}
});
}
Example #5
Source File: socket-io.adapter.ts From nativescript-plugins with Apache License 2.0 | 5 votes |
constructor(
appOrHttpServer?: INestApplicationContext | any,
private readonly corsOrigins = [],
) {
super(appOrHttpServer);
}
Example #6
Source File: nest-application-context.d.ts From nest-jaeger with MIT License | 4 votes |
/**
* @publicApi
*/
export declare class NestApplicationContext implements INestApplicationContext {
protected readonly container: NestContainer;
private readonly scope;
private contextModule;
protected isInitialized: boolean;
protected readonly injector: Injector;
private shutdownCleanupRef?;
private readonly activeShutdownSignals;
private _instanceLinksHost;
private get instanceLinksHost();
constructor(container: NestContainer, scope?: Type<any>[], contextModule?: Module);
selectContextModule(): void;
select<T>(moduleType: Type<T>): INestApplicationContext;
get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Abstract<TInput> | string | symbol, options?: {
strict: boolean;
}): TResult;
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | string | symbol, contextId?: ContextId, options?: {
strict: boolean;
}): Promise<TResult>;
registerRequestByContextId<T = any>(request: T, contextId: ContextId): void;
/**
* Initalizes the Nest application.
* Calls the Nest lifecycle events.
*
* @returns {Promise<this>} The NestApplicationContext instance as Promise
*/
init(): Promise<this>;
close(): Promise<void>;
useLogger(logger: LoggerService): void;
/**
* Enables the usage of shutdown hooks. Will call the
* `onApplicationShutdown` function of a provider if the
* process receives a shutdown signal.
*
* @param {ShutdownSignal[]} [signals=[]] The system signals it should listen to
*
* @returns {this} The Nest application context instance
*/
enableShutdownHooks(signals?: (ShutdownSignal | string)[]): this;
protected dispose(): Promise<void>;
/**
* Listens to shutdown signals by listening to
* process events
*
* @param {string[]} signals The system signals it should listen to
*/
protected listenToShutdownSignals(signals: string[]): void;
/**
* Unsubscribes from shutdown signals (process events)
*/
protected unsubscribeFromProcessSignals(): void;
/**
* Calls the `onModuleInit` function on the registered
* modules and its children.
*/
protected callInitHook(): Promise<void>;
/**
* Calls the `onModuleDestroy` function on the registered
* modules and its children.
*/
protected callDestroyHook(): Promise<void>;
/**
* Calls the `onApplicationBootstrap` function on the registered
* modules and its children.
*/
protected callBootstrapHook(): Promise<void>;
/**
* Calls the `onApplicationShutdown` function on the registered
* modules and children.
*/
protected callShutdownHook(signal?: string): Promise<void>;
/**
* Calls the `beforeApplicationShutdown` function on the registered
* modules and children.
*/
protected callBeforeShutdownHook(signal?: string): Promise<void>;
protected find<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Abstract<TInput> | string | symbol, contextModule?: Module): TResult;
protected resolvePerContext<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | string | symbol, contextModule: Module, contextId: ContextId, options?: {
strict: boolean;
}): Promise<TResult>;
}