TSyringe: Lightweight Dependency Injection for TypeScript/JavaScript
This repository profile is provided by osrepos.com, an open source repository discovery platform.
Summary
TSyringe is a lightweight dependency injection (DI) container developed by Microsoft for JavaScript and TypeScript applications. It provides a robust solution for managing class dependencies, making your codebase more modular, testable, and maintainable. By leveraging decorators, TSyringe simplifies the process of injecting dependencies into your classes, adhering to the Inversion of Control (IoC) principle.
Repository Information
Topics
Click on any tag to explore related repositories
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Introduction
TSyringe is a lightweight dependency injection (DI) container developed by Microsoft for JavaScript and TypeScript applications. It provides a robust solution for managing class dependencies, making your codebase more modular, testable, and maintainable. By leveraging decorators, TSyringe simplifies the process of injecting dependencies into your classes, adhering to the Inversion of Control (IoC) principle.
Installation
To get started with TSyringe, you need to install it via npm or yarn and configure your TypeScript project.
First, install the package:
npm install --save tsyringe
# or
yarn add tsyringe
Next, modify your tsconfig.json to enable experimental decorators and emit decorator metadata:
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
Finally, add a polyfill for the Reflect API, typically reflect-metadata, at the entry point of your application:
// main.ts
import "reflect-metadata";
// Your application code here...
Examples
TSyringe makes it straightforward to inject dependencies, especially when working with interfaces to promote loose coupling. Here's an example demonstrating dependency injection with interfaces:
// SuperService.ts
export interface SuperService {
doSomething(): string;
}
// TestService.ts
import { SuperService } from "./SuperService";
export class TestService implements SuperService {
doSomething(): string {
return "Hello from TestService!";
}
}
// Client.ts
import { injectable, inject } from "tsyringe";
import { SuperService } from "./SuperService";
@injectable()
export class Client {
constructor(@inject("SuperService") private service: SuperService) {}
execute(): string {
return `Client executing: ${this.service.doSomething()}`;
}
}
// main.ts
import "reflect-metadata";
import { container } from "tsyringe";
import { Client } from "./Client";
import { TestService } from "./TestService";
// Register the implementation for the 'SuperService' token
container.register("SuperService", {
useClass: TestService
});
const client = container.resolve(Client);
console.log(client.execute()); // Output: Client executing: Hello from TestService!
Why Use TSyringe?
Adopting a dependency injection container like TSyringe offers several significant advantages for your projects:
- Improved Testability: Dependencies can be easily mocked or swapped out during unit testing, simplifying the testing process.
- Loose Coupling: Components are less dependent on concrete implementations, making your codebase more flexible and easier to refactor.
- Enhanced Maintainability: Centralized management of dependencies reduces boilerplate code and makes it easier to understand and modify how components interact.
- Scalability: Supports the development of larger, more complex applications by providing a structured way to manage dependencies across many modules.
- Clearer Code Structure: Promotes a clean architecture and adherence to SOLID principles, leading to more organized and readable code.
Links
For more detailed information, documentation, and to contribute, visit the official TSyringe resources:
Related repositories
Similar repositories that may be relevant next.

CubeSandbox: Instant, Concurrent, and Secure Sandbox for AI Agents
August 9, 2026
CubeSandbox, developed by TencentCloud, is a high-performance, secure sandbox service built on RustVMM and KVM, designed specifically for AI agents. It offers ultra-fast startup times, hardware-level isolation, and high-density deployment, making it ideal for scalable and secure agent execution environments. The service is also fully compatible with the E2B SDK for seamless integration.

dockur/macos: Run macOS in a Docker Container with KVM Acceleration
October 12, 2025
dockur/macos is an innovative GitHub project that enables users to run macOS within a Docker container, leveraging KVM acceleration for optimal performance. This solution simplifies the process of setting up a macOS virtual machine, offering a web-based viewer and automatic download of macOS images. It provides a highly convenient and flexible way to access a macOS environment for various purposes, including development and testing.
Source repository
Open the original repository on GitHub.
9 counted GitHub visits