-
Notifications
You must be signed in to change notification settings - Fork 0
inject config
awekrx edited this page May 29, 2026
·
1 revision
import { injectConfig } from '@dev-suite/decorators/inject-config'
class
Inject shared configuration into class instances without repeating constructor plumbing.
- Passing the same config object through many constructors
- Manual
this.config = ...setup per class
class StripeAdapter {
private readonly config: { apiKey: string; region: string };
constructor(config: { apiKey: string; region: string }) {
this.config = config;
}
createCharge() {
return this.client.charge({ key: this.config.apiKey, region: this.config.region });
}
}import { injectConfig } from '@dev-suite/decorators/inject-config';
@injectConfig({
config: {
apiKey: process.env.STRIPE_API_KEY,
region: 'us-east-1',
},
})
class StripeAdapter {
createCharge() {
return this.client.charge({ key: this.config.apiKey, region: this.config.region });
}
}- Removes repeated config constructor signatures
- Co-locates adapter config with class definition
class MailgunAdapter {
constructor(private readonly cfg: { domain: string; token: string }) {}
send(payload: MailPayload) {
return this.client.send({ ...payload, domain: this.cfg.domain, token: this.cfg.token });
}
}import { injectConfig } from '@dev-suite/decorators/inject-config';
@injectConfig({ config: { domain: 'mg.example.com', token: process.env.MAILGUN_TOKEN } })
class MailgunAdapter {
send(payload: MailPayload) {
return this.client.send({ ...payload, domain: this.config.domain, token: this.config.token });
}
}- Standardized configuration shape across adapters
- Easier instantiation in tests and factories