Skip to content

Commit 996461a

Browse files
docs: add docs on extra providers attribute #3029
1 parent 1045661 commit 996461a

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

content/techniques/caching.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ $ npm install @nestjs/cache-manager cache-manager
1111
```
1212

1313
> warning **Warning** `cache-manager` version 4 uses seconds for `TTL (Time-To-Live)`. The current version of `cache-manager` (v5) has switched to using milliseconds instead. NestJS doesn't convert the value, and simply forwards the ttl you provide to the library. In other words:
14-
> * If using `cache-manager` v4, provide ttl in seconds
15-
> * If using `cache-manager` v5, provide ttl in milliseconds
16-
> * Documentation is referring to seconds, since NestJS was released targeting version 4 of cache-manager.
14+
>
15+
> - If using `cache-manager` v4, provide ttl in seconds
16+
> - If using `cache-manager` v5, provide ttl in milliseconds
17+
> - Documentation is referring to seconds, since NestJS was released targeting version 4 of cache-manager.
1718
1819
#### In-memory cache
1920

@@ -315,6 +316,18 @@ This works the same as `useClass` with one critical difference - `CacheModule` w
315316
316317
> info **Hint** `CacheModule#register` and `CacheModule#registerAsync` and `CacheOptionsFactory` has an optional generic (type argument) to narrow down store-specific configuration options, making it type safe.
317318
319+
You can also pass so-called `extraProviders` to the `registerAsync()` method. These providers will be merged with the module providers.
320+
321+
```typescript
322+
CacheModule.registerAsync({
323+
imports: [ConfigModule],
324+
useClass: ConfigService,
325+
extraProviders: [MyAdditionalProvider],
326+
});
327+
```
328+
329+
This is useful when you want to provide additional dependencies to the factory function or the class constructor.
330+
318331
#### Example
319332
320333
A working example is available [here](https://github.com/nestjs/nest/tree/master/sample/20-cache).

content/techniques/file-upload.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export abstract class FileValidator<TValidationOptions = Record<string, any>> {
118118
`FileValidator` is a regular class that has access to the file object and validates it according to the options provided by the client. Nest has two built-in `FileValidator` implementations you can use in your project:
119119

120120
- `MaxFileSizeValidator` - Checks if a given file's size is less than the provided value (measured in `bytes`)
121-
- `FileTypeValidator` - Checks if a given file's mime-type matches the given value.
121+
- `FileTypeValidator` - Checks if a given file's mime-type matches the given value.
122122

123123
> warning **Warning** To verify file type, [FileTypeValidator](https://github.com/nestjs/nest/blob/master/packages/common/pipes/file/file-type.validator.ts) class uses the type as detected by multer. By default, multer derives file type from file extension on user's device. However, it does not check actual file contents. As files can be renamed to arbitrary extensions, consider using a custom implementation (like checking the file's [magic number](https://www.ibm.com/support/pages/what-magic-number)) if your app requires a safer solution.
124124
@@ -135,6 +135,7 @@ To understand how these can be used in conjunction with the aforementioned `File
135135
)
136136
file: Express.Multer.File,
137137
```
138+
138139
> info **Hint** If the number of validators increase largely or their options are cluttering the file, you can define this array in a separate file and import it here as a named constant like `fileValidators`.
139140
140141
Finally, you can use the special `ParseFilePipeBuilder` class that lets you compose & construct your validators. By using it as shown below you can avoid manual instantiation of each validator and just pass their options directly:
@@ -318,6 +319,18 @@ MulterModule.registerAsync({
318319
});
319320
```
320321

322+
You can also pass so-called `extraProviders` to the `registerAsync()` method. These providers will be merged with the module providers.
323+
324+
```typescript
325+
MulterModule.registerAsync({
326+
imports: [ConfigModule],
327+
useClass: ConfigService,
328+
extraProviders: [MyAdditionalProvider],
329+
});
330+
```
331+
332+
This is useful when you want to provide additional dependencies to the factory function or the class constructor.
333+
321334
#### Example
322335

323336
A working example is available [here](https://github.com/nestjs/nest/tree/master/sample/29-file-upload).

content/techniques/http-module.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ HttpModule.registerAsync({
132132
});
133133
```
134134

135+
You can also pass so-called `extraProviders` to the `registerAsync()` method. These providers will be merged with the module providers.
136+
137+
```typescript
138+
HttpModule.registerAsync({
139+
imports: [ConfigModule],
140+
useClass: HttpConfigService,
141+
extraProviders: [MyAdditionalProvider],
142+
});
143+
```
144+
145+
This is useful when you want to provide additional dependencies to the factory function or the class constructor.
146+
135147
#### Using Axios directly
136148

137149
If you think that `HttpModule.register`'s options are not enough for you, or if you just want to access the underlying Axios instance created by `@nestjs/axios`, you can access it via `HttpService#axiosRef` as follows:

0 commit comments

Comments
 (0)