Skip to content

v2.3.0

Choose a tag to compare

@github-actions github-actions released this 09 Feb 07:49
· 5 commits to master since this release

New Features

Runtime captive dependency detection

Katagami now detects captive dependencies at runtime within scopes, in addition to existing compile-time prevention. If a singleton factory attempts to resolve a scoped token — directly or through intermediaries — a ContainerError is thrown with a clear message.

const container = createContainer()
  .registerScoped(RequestContext, () => new RequestContext())
  .registerSingleton(DbPool, r => new DbPool(r.resolve(RequestContext)));

const scope = createScope(container);
scope.resolve(DbPool);
// ContainerError: Captive dependency detected: scoped token "RequestContext"
//   cannot be resolved inside a singleton factory.

This uses a depth-tracking mechanism (singletonDepth) to detect when a scoped token is being resolved inside a singleton factory chain, catching issues that type-level checks alone cannot prevent (e.g., @ts-expect-error or any casts).

Both resolve() and tryResolve() / resolveAll() / tryResolveAll() enforce this rule.

Documentation

  • Added DI container comparison table to all multilingual README files

Full Changelog: v2.2.0...v2.3.0