TSyringe provides constructor injection for TypeScript and JavaScript using decorators and a configurable container.
Overview
TSyringe is a dependency injection container aimed at TypeScript and JavaScript codebases that want constructor injection without a heavy framework. You register providers, mark classes with decorators, and resolve instances from a container that understands tokens, scopes, and child containers.
The API centers on decorators such as injectable, singleton, scoped, and inject for tokens and interface-style dependencies. Registration can happen through explicit register calls, registries on classes, and provider types including class, value, factory, and token aliases. Resolution supports singleton and scoped lifecycles, child containers, interception, and helpers for circular dependencies.
The project targets teams already using TypeScript metadata and typical npm installs with yarn or npm. Babel and React Native setups need extra configuration so metadata is emitted for injection. Examples in the documentation cover constructor injection with and without interfaces, named primitive injection, and disposable instances.
It is maintained as a focused IoC library rather than a full application framework, so you integrate it into existing apps and choose your own structure around the container.
Key features
- Constructor injection with decorators
- Singleton and scoped lifecycles
- Injection tokens and provider types
- Child containers and interception
- Factory and value providers
- Registry-based registration
- Circular dependency helpers
- Optional and multi-injection parameters
Use cases
- Wiring services in Node or web backends
- Managing test doubles with scoped containers
- Sharing singletons across application modules
- Injecting interface tokens in TypeScript
- Composing child containers per request