Skip to content

v2.2.0

Choose a tag to compare

@github-actions github-actions released this 09 Feb 06:10
· 7 commits to master since this release

New Features

Multi-binding with resolveAll() / tryResolveAll()

Multiple factories can now be registered for the same token. resolve() returns the instance from the last registered factory, while resolveAll() returns instances from all factories in registration order.

const container = createContainer()
  .registerSingleton(Logger, () => new ConsoleLogger())
  .registerSingleton(Logger, () => new FileLogger());

container.resolve(Logger);    // FileLogger (last registered)
container.resolveAll(Logger); // [ConsoleLogger, FileLogger]

tryResolveAll() returns undefined instead of throwing when the token is not registered.

Per-registration singleton cache

Singleton caching is now per-registration rather than per-token. Each registered factory maintains its own independent cache, enabling correct behavior with multi-binding.

Lazy resolution with lazy()

The new katagami/lazy subpath export provides lazy() — a Proxy-based deferred instantiation function. The instance is not created until the first property access, then cached for subsequent accesses.

import { lazy } from 'katagami/lazy';

const service = lazy(container, HeavyService);
// HeavyService is NOT instantiated yet

service.process(); // instance created here, then cached

Only sync class tokens are supported — async tokens and PropertyKey tokens are rejected at the type level.

Bug Fixes

  • Removed unused ServiceA class from multi.test.ts files

Full Changelog: v2.1.0...v2.2.0