Skip to content

Commit

Permalink
fix: unable to read configuration providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Val-istar-Guo committed Jan 18, 2024
1 parent 42009af commit 05fce44
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Import `ConfigModule` in your `AppModule`:
// app.module.ts
import { Module } from "@nestjs/common";
import { ConfigModule } from "@buka/nestjs-config";
import { AppConfig } from './app.config'

@Module({
// use process.env and read .env by defaulted
Expand All @@ -84,8 +85,6 @@ import { ConfigModule } from "@buka/nestjs-config";
export class AppModule {}
```

> `ConfigModule` automatically loads all classes with the `@Configuration` decorator.
Inject and use `AppConfig` in your service:

```typescript
Expand Down
2 changes: 2 additions & 0 deletions src/decorators/configuration.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { CONFIGURATION_OBJECTS_METADATA_KEY, CONFIGURATION_OBJECT_PATH_METADATA_


export function Configuration(path?: string): ClassDecorator {
console.log('🚀 ~ Configuration ~ path:', path)
return (target) => {
console.log('🚀 ~ return ~ target:', target)
Reflect.defineMetadata(CONFIGURATION_OBJECT_PATH_METADATA_KEY, path, target)

const configurations = Reflect.getMetadata(CONFIGURATION_OBJECTS_METADATA_KEY, ConfigModule) || []
Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/config-module-options.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* ConfigModuleOptions['providers] field doesn't seem to have any practical effect.
* In fact, it ensures that the classes decorated by @Configuration() can be loaded before the ConfigModule.register().
* Further ensures that ConfigModule can read all classes decorated by @Configuration() from Reflect.
*/
import { Type } from '@nestjs/common'
import { ConfigLoader } from './config-loader.interface.js'

export interface ConfigModuleOptions {
Expand All @@ -6,5 +12,7 @@ export interface ConfigModuleOptions {
*/
config?: (string | ConfigLoader)[]

providers: Type[]

suppressWarnings?: true
}

0 comments on commit 05fce44

Please sign in to comment.