You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The standalone application object allows you to obtain a reference to any instance registered within the Nest application. Let's imagine that we have a `TasksService` in the `TasksModule`. This class provides a set of methods that we want to call from within a CRON job.
18
+
#### Retrieving providers for static modules
19
+
20
+
The standalone application object allows you to obtain a reference to any instance registered within the Nest application.
21
+
Let's imagine that we have a `TasksService` provider in the `TasksModule` module that was imported by our `AppModule` module. This class provides a set of methods that we want to call from within a CRON job.
To access the `TasksService` instance we use the `get()` method. The `get()` method acts like a **query** that searches for an instance in each registered module. Alternatively, for strict context checking, pass an options object with the `strict: true` property. With this option in effect, you have to navigate through specific modules to obtain a particular instance from the selected context.
29
+
To access the `TasksService` instance we use the `get()` method.
30
+
The `get()` method acts like a **query** that searches for an instance in each registered module. You can pass any provider's token to it. Alternatively, for strict context checking, pass an options object with the `strict: true` property. With this option in effect, you have to navigate through specific modules to obtain a particular instance from the selected context.
@@ -54,7 +58,32 @@ Following is a summary of the methods available for retrieving instance referenc
54
58
55
59
> info **Hint** In non-strict mode, the root module is selected by default. To select any other module, you need to navigate the modules graph manually, step by step.
56
60
57
-
If you want the node application to close after the script finishes (e.g., for a script running CRON jobs), add `await app.close()` to the end of your `bootstrap` function:
61
+
#### Retrieving providers for dynamic modules
62
+
63
+
When dealing with [dynamic modules](./fundamentals/dynamic-modules.md), we should supply the same object that represents the registered dynamic module in the application to `app.select`. For example:
this is because we didn't registered the static version of `ConfigModule`, only the dynamic version.
83
+
84
+
#### Terminating phase
85
+
86
+
If you want the Node application to close after the script finishes (e.g., for a script running CRON jobs), you must call the `app.close()` method in the end of your `bootstrap` function like this:
58
87
59
88
```typescript
60
89
@@filename()
@@ -66,6 +95,8 @@ async function bootstrap() {
66
95
bootstrap();
67
96
```
68
97
98
+
And as mentioned at [Lifecycle events](./fundamentals/lifecycle-events.md) chapter, that will trigger few lifecycle hooks.
99
+
69
100
#### Example
70
101
71
102
A working example is available [here](https://github.com/nestjs/nest/tree/master/sample/18-context).
0 commit comments