This page is also available in Italiano.

Continua in italiano

FAQ

Does TinyDI support automatic constructor injection?
No, by design. You wire up constructor arguments yourself inside a factory ((c) => new UserService(c.resolve(UserRepositoryToken))). This is the core trade-off TinyDI makes: more explicit code, no reflection.
Can I register the same token twice, to override it?
Not directly — a second registration on an already-registered token throws RegistrationError. Call container.remove(token) first (or container.clear() to reset everything), then register again. This is useful for swapping implementations in tests.
Does TinyDI support scoped (per-request) lifetimes?
Not in this version — only Singleton and Transient exist today. The design intentionally doesn't preclude adding a scoped lifetime later, but it isn't part of the current API.
Does TinyDI support child containers?
Not in this version. Each Container is fully self-contained with no shared global state, which leaves the door open for a parent/child relationship in a future version without requiring a redesign.
Is TinyDI tied to Node.js?
No — it has zero runtime dependencies and uses no Node-specific APIs, so it runs unmodified on Bun, Deno and in the browser.
Can a factory be asynchronous?
Factory<T> is synchronous by design ((container: Container) => T). If you need to build something asynchronously, resolve a promise-returning value as the service itself (Token<Promise<T>>) and await it at the call site — TinyDI does not currently ship a dedicated async resolution API.
to navigate to select Esc to close