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
[RFC] ConfigModule for NexusDI (Resolver-Based, Type-Safe, Group-Friendly, Refreshable)
Overview
The ConfigModule provides centralized, type-safe, and environment-aware configuration for NexusDI projects. It is designed around a resolver pattern (for pluggable config sources) and supports grouping/namespacing, schema validation, seamless integration with DI and dynamic module configuration, and refreshable/dynamic config for providers like Azure AppConfig, AWS AppConfig, or Kubernetes ConfigMaps.
Motivation
Centralized config: Avoid scattered config logic and magic strings throughout the codebase.
Type safety: Enable type-checked configuration objects for better DX and fewer runtime errors.
Environment awareness: Support for environment-specific config (dev, prod, test, etc.).
Integration: Allow modules and plugins to declare and consume config via DI or via .config/.configAsync.
Secrets management: Optionally support loading secrets from files, env, or secret managers.
// Synchronous configimport{UserModule}from'./user/user.module';import{ConfigService}from'@nexusdi/config';constuserConfig=container.get(ConfigService).get('user');container.set(UserModule.config(userConfig));// Async config (e.g., if config is loaded from a remote source)constuserModule=awaitUserModule.configAsync(async()=>{constconfigService=container.get(ConfigService);returnawaitconfigService.getAsync('user');});container.set(userModule);// Or inline:container.set(awaitUserModule.configAsync(async()=>{constconfigService=container.get(ConfigService);returnawaitconfigService.getAsync('user');}));
Refreshable Config: Manual and Event-Driven
// Manual refresh (e.g., on a timer or webhook)setInterval(()=>{configService.refresh();},60000);// React to changesconfigService.onChange(()=>{// Reload or update dependent services, clear caches, etc.});
Refreshable Config: Design Details
Resolver API:
Resolvers can optionally implement a refresh() method or emit a change event.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
[RFC] ConfigModule for NexusDI (Resolver-Based, Type-Safe, Group-Friendly, Refreshable)
Overview
The ConfigModule provides centralized, type-safe, and environment-aware configuration for NexusDI projects. It is designed around a resolver pattern (for pluggable config sources) and supports grouping/namespacing, schema validation, seamless integration with DI and dynamic module configuration, and refreshable/dynamic config for providers like Azure AppConfig, AWS AppConfig, or Kubernetes ConfigMaps.
Motivation
.config/.configAsync.Proposed Features
.env, JSON/YAML files, AWS SSM/Secrets Manager, Kubernetes, Azure AppConfig, etc.ConfigService(or similar) that can be injected into any provider.config.dev.json,config.prod.json)..configand.configAsyncusing the config module.refresh()oronChange();ConfigServiceexposesrefresh()andonChange()for runtime updates.Example Workflow
Define config files:
config.json(base config)config.dev.json(development overrides)config.prod.json(production overrides).env(environment variables)Define a config schema (optional but recommended):
Register the config module with resolvers and schema:
Inject and use the config service or config groups:
Use in dynamic module config (sync and async):
Refreshable Config: Manual and Event-Driven
Refreshable Config: Design Details
Resolver API:
Resolvers can optionally implement a
refresh()method or emit a change event.ConfigService API:
refresh(): Manually trigger a refresh across all resolvers.onChange(callback): Subscribe to config changes.Consumer Usage:
configService.refresh()for manual refresh (e.g., polling, webhooks).configService.onChange()for event-driven updates.Injection:
Open Questions
API Sketch
Call for Feedback
Beta Was this translation helpful? Give feedback.
All reactions