- Lifecycle:
active - Maintainer/Owner:
TBD - Last reviewed:
TBD
Lightweight dependency container package used across multiple org repositories to provide deterministic service resolution with minimal DI boilerplate.
Primary implementation file: container.ts
Core concepts:
Injectable<T>token can be class constructor or factory function- singleton instance registry (
instances) - provider registry for transient/fresh resolution (
providers) - memoization cache (
memos)
Resolution flow:
app(service)delegates toContainer.resolve.- Missing services auto-register using constructor/factory.
fresh=truereturns new provider instance without replacing singleton cache.
- Node.js (LTS)
- npm
npm install
npm run buildnpm run build
npm publish --access public
# or
npm run publish:publicNo environment variables are required by this library package.
| Variable | Required | Default | Example | Secret | Used by | Notes |
|---|---|---|---|---|---|---|
| None | N/A | N/A | N/A | N/A | N/A | Runtime behavior is config-free |
npm run build- Unexpected stale singleton: use
Container.unregister(Service)and resolve again. - Stale memoized result: call
Container.refresh(fn)before reuse.
Resolve service from container.
const client = app(ApiClient);
const transient = app(ApiClient, true);Bind abstraction to implementation.
Container.register(DatabaseClient, () => new PostgresClient());Low-level equivalent of app.
Memoize pure function by argument signature.
const fib = Container.memo((n: number): number => {
return n < 2 ? n : fib(n - 1) + fib(n - 2);
});- Avoid storing secrets in singleton services directly; inject secret providers instead.
- Memoization stores return values in-memory; do not memoize sensitive material unless required.
- Branch from
main. - Implement API-compatible changes in
container.ts. - Build and verify package output:
npm run build- Update README usage examples for any API changes.
- Publish only from reviewed tags/releases.
- Preserve backwards compatibility for
app,register,resolve, andmemo. - Keep TypeScript output and declaration files stable.
- Document behavioral changes with migration notes in README and release notes.