forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshutdown.module.ts
More file actions
29 lines (28 loc) 路 1.19 KB
/
Copy pathshutdown.module.ts
File metadata and controls
29 lines (28 loc) 路 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Module } from '@nestjs/common';
import { InFlightRequestTracker } from './in-flight-tracker.service';
import { InFlightRequestMiddleware } from './in-flight.middleware';
/**
* # ShutdownModule
*
* Provides the in-flight request tracker and the Express middleware that
* feeds it.
*
* ## Why `ShutdownService` is NOT registered here
*
* `ShutdownService` depends on the running `INestApplication` instance,
* which is only available after `NestFactory.create()` finishes and the
* application context has been initialised. Resolving it through DI would
* either require a custom factory provider or an `APP_INITIALIZER` hook.
* Instead the service is instantiated manually in `main.ts` and cached
* for the lifetime of the process. Registration here would be misleading
* because nothing in `main.ts` resolves it from the container.
*
* If you need to consume `ShutdownService` from another Nest provider,
* expose it from `main.ts` as a custom token (e.g. `app.get(SHUTDOWN_SERVICE_TOKEN)`)
* after instantiating it.
*/
@Module({
providers: [InFlightRequestTracker, InFlightRequestMiddleware],
exports: [InFlightRequestTracker, InFlightRequestMiddleware],
})
export class ShutdownModule {}