Introduction
@navios/di is a dependency injection container for TypeScript. A class marked @Injectable() declares what it needs with inject(), and a container builds it together with everything it depends on.
There is no module file to maintain and no list of providers to keep in sync. A class registers itself when it is decorated, and a container finds it through the class.
Design principles
Where it is used
The container has no knowledge of HTTP, React or the command line. Each of these builds on it:
- Navios server. Controllers, guards and services are injectable classes, and a request that uses a request-scoped service gets its own scope.
@navios/serverre-exports the DI API, so server code imports it from there. Start at Services and injection. - React.
@navios/di-reactputs a container in context and resolves services in components with hooks. Start at the React quick start. - Commander. CLI commands are injectable classes resolved from the same kind of container. See Dependency injection in Commander.
- On its own. Scripts, workers and libraries can create a
Containerdirectly. The Quick start does exactly that.
It runs unchanged on Node.js, Bun, Deno and in the browser.