Wireit
⚡ Quick Reference
Package: @vielzeug/wireit · Category: Di
Key exports: createContainer, createToken
When to use: Type-safe DI container with singleton/transient lifetimes, child scopes, async providers, and circular dependency detection.
@vielzeug/wireit is a compact dependency injection container built around typed symbol tokens, factory registration, and explicit container scopes.
Installation
sh
pnpm add @vielzeug/wireitsh
npm install @vielzeug/wireitsh
yarn add @vielzeug/wireitQuick Start
ts
import { createContainer, createToken } from '@vielzeug/wireit';
const Logger = createToken<{ log(message: string): void }>('Logger');
const Service = createToken<{ run(): Promise<void> }>('Service');
const container = createContainer();
container.value(Logger, console);
container.factory(Service, (logger) => ({ run: async () => logger.log('Running service') }), {
deps: [Logger],
});
const service = await container.resolve(Service);
await service.run();
await container.dispose();Why Wireit?
Manual dependency wiring often spreads across modules, making lifetimes and teardown behavior difficult to reason about in larger systems.
| Feature | Wireit | tsyringe | InversifyJS |
|---|---|---|---|
| Bundle size | 1.2 KB | ~6 kB | ~45 kB |
| Typed token ergonomics | ✅ | Partial | Partial |
| Async-first resolution | ✅ | Partial | Partial |
| Child container scopes | ✅ | ✅ | ✅ |
| Explicit disposal lifecycle | ✅ | ❌ | Partial |
| Decorator-free usage | ✅ | ❌ (decorator-oriented) | ⚠️ (commonly decorator-oriented) |
| Zero dependencies | ✅ | ✅ | ❌ |
Use Wireit when you need a compact typed container with explicit scopes and lifecycle control.
Consider decorator-heavy DI frameworks when your project is already standardized around metadata/decorator injection patterns.
Features
- Small core API
- Typed dependency contracts
- Async-first resolution
- Child containers for scope boundaries
- Explicit disposal
Compatibility
| Environment | Support |
|---|---|
| Browser | ✅ |
| Node.js | ✅ |
| SSR | ✅ |
| Deno | ✅ |