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
Copy file name to clipboardexpand all lines: content/fundamentals/discovery-service.md
+8-8
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,11 @@
2
2
3
3
The `DiscoveryService` is a utility provided by `@nestjs/core` that allows developers to dynamically discover providers, controllers, and other metadata within a NestJS application. This can be particularly useful for building plugins, decorators, or features that rely on runtime introspection.
4
4
5
-
## Installation
5
+
###Installation
6
6
7
7
`DiscoveryService` is part of `@nestjs/core`, so it does not require separate installation. You can use it directly within your NestJS application.
8
8
9
-
## Importing DiscoveryService and DiscoveryModule
9
+
###Importing DiscoveryService and DiscoveryModule
10
10
11
11
Before using the `DiscoveryService`, you need to import the `DiscoveryModule` in your module:
12
12
@@ -43,9 +43,9 @@ export class ExampleService {
43
43
44
44
> info **Hint** The `DiscoveryService` class is imported from the `@nestjs/core` package.
45
45
46
-
## Use Cases
46
+
###Use Cases
47
47
48
-
### 1. Discovering Providers
48
+
####1. Discovering Providers
49
49
50
50
You can retrieve all registered providers in the application:
51
51
@@ -56,7 +56,7 @@ console.log(providers);
56
56
57
57
Each provider object contains information about the instance, token, and metadata.
console.log('Providers with custom metadata:', filteredProviders);
115
115
```
116
116
117
-
## Conclusion
117
+
###Conclusion
118
118
119
119
`DiscoveryService` is a powerful tool for runtime introspection in NestJS applications. It allows you to discover providers, controllers, and metadata dynamically, making it useful for plugin development, custom decorators, and advanced framework-level features.
0 commit comments