Skip to content

v2.1.0

Choose a tag to compare

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

New Features

Module composition with use()

Containers can now be composed via use() to group and reuse registrations. Define reusable modules as containers and apply them to other containers — only registration entries are copied, singleton instance caches are not shared.

const authModule = createContainer()
  .registerSingleton(AuthService, () => new AuthService())
  .registerSingleton(TokenService, () => new TokenService());

const container = createContainer()
  .use(authModule)
  .registerSingleton(UserService, r => new UserService(r.resolve(AuthService)));

Optional resolution with tryResolve()

tryResolve() returns undefined for unregistered tokens instead of throwing ContainerError. Useful for optional dependencies in factories.

const analytics = container.tryResolve(Analytics);
//    ^? Analytics | undefined

DisposableContainer / DisposableScope types

The disposable() wrapper now returns narrowed types (DisposableContainer or DisposableScope) that only expose resolve and tryResolve — registration methods are excluded at the type level, preventing accidental registration on a potentially-disposed container.

createScope() accepts disposable sources

createScope() now accepts DisposableContainer and DisposableScope in addition to Container and Scope.

Documentation

  • Updated all multilingual README files with new API documentation

Full Changelog: v2.0.0...v2.1.0