TypeScript library · v2.0.0
@zirion/ioc
A lightweight, dependency-free IoC container for Node.js with constructor injection, lazy resolution, and singleton and request-scoped lifetimes.
@zirion/ioc is a compact Inversion of Control container for Node.js applications. It keeps dependency management explicit without bringing runtime dependencies into a project.
What it provides
- Constructor injection for classes and registered values.
- Singleton and request-scoped provider lifetimes.
- Context objects for request-scoped dependencies.
- Lazy dependency resolution.
- A fluent container builder and no runtime dependencies.
Install
npm install @zirion/ioc
Continue with the complete Dependency Injection guide for scopes, asynchronous factories, lifecycle hooks, testing patterns, errors, migration notes, and the public API reference.
The package is open source under the MIT license. The current roadmap is available in the repository.
Release history
- Made container resolution asynchronous:
get()andgetOrFail()now return promises. - Replaced provider
valuewith an async-capablevalueFactoryAPI. - Added typed container composition: each
add()call carries registered selectors into the resulting container type. - Added object selectors and support for factories that return either values or class constructors.
- Added configurable logging with a default console logger and exported logger interfaces.
- Added the
onInitializedlifecycle hook andbuild()as an alias forfinalize(). finalize()now supports registered objects as well as class instances and returns the built container.
- Removed the package-level prebuilt container export; consumers now create their own
Containerinstance. - Improved return-type inference for class selectors in
get()andgetOrFail(). - Simplified package exports and removed the
@zirion/ioc/containerentry point. - Declared Node.js 18+ support and added browser compatibility metadata.
- Updated documentation and package discovery keywords.
- Fixed the finalized lifecycle hook lookup: the container now correctly calls
onFinalized(). - Added test execution to the package release checks.
- Updated the TypeScript, ESLint, Vitest, and Node.js type toolchain.
- Added structured
DependencyInjectionErrorerrors and exported error codes for container failures. - Added validation for missing and duplicate targets, unknown selectors and scopes, and invalid resolvers.
- Added explicit errors for missing request contexts and invalid singleton-to-request dependency graphs.
- Fixed singleton caching so resolved instances are reused.
- Added utilities for readable selector names, broader test coverage, and coverage reporting.
- Maintenance publication aligning the package version metadata with the npm release.
- Reworked the package structure and public entry points.
- Added separate CommonJS, ES module, and declaration builds.
- Added package documentation, usage examples, and contributing guidelines.
- Added dependency update and stale-issue automation for the repository.
- Initial npm release of the IoC container.
- Added provider registration and lazy dependency resolution.
- Added constructor injection with singleton and request-scoped lifetimes.
- Added context-based caching for request-scoped providers and the
onFinalizedlifecycle contract.
Interactive example
Try @zirion/ioc
Edit the example and run it locally in your browser. No code is sent anywhere.
Output
Ready. Press Run code or ⌘/Ctrl + Enter.