Skip to content

Conversation

mag123c
Copy link

@mag123c mag123c commented Aug 7, 2025

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Currently, TerminusModule only supports static configuration through the forRoot() method. This prevents users from dynamically injecting configuration from services like ConfigService or using environment variables at runtime.

Issue Number: #2649

What is the new behavior?

This PR adds forRootAsync() method to TerminusModule that enables dynamic configuration injection. Users can now:

  • Use useFactory to dynamically create configuration with dependency injection
  • Use useClass to provide a configuration factory class
  • Use useExisting to reuse an existing configuration factory provider

Example usage:

TerminusModule.forRootAsync({
  imports: [ConfigModule],
  inject: [ConfigService],
  useFactory: (configService: ConfigService) => ({
    gracefulShutdownTimeoutMs: configService.get('TERMINUS_SHUTDOWN_TIMEOUT', 5000),
    errorLogStyle: configService.get('TERMINUS_LOG_STYLE', 'json'),
    logger: configService.get('TERMINUS_LOGGER_ENABLED', true),
  }),
})

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

I have a sample application ready that demonstrates the forRootAsync usage with ConfigModule and environment variables. Should I include it as sample/013-forrootasync-app (similar to other sample apps in the repository)?

The sample would show:

  • Integration with @nestjs/config
  • Environment-based configuration
  • All three patterns (useFactory, useClass, useExisting)

Let me know if you'd like me to add it to this PR or keep the PR focused on the core implementation only.

@mag123c
Copy link
Author

mag123c commented Aug 27, 2025

ci e2e fail reason: #2672

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant