You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lightweight and powerful dependency injection container for TypeScript applications
9
+
10
+
---
11
+
12
+
## Overview
13
+
14
+
**first-di** is a modern, type-safe dependency injection container designed specifically for TypeScript applications. It provides a clean and intuitive API for managing dependencies with minimal configuration and zero runtime dependencies.
15
+
16
+
### Key Features
17
+
18
+
- 🚀 **Zero Dependencies** - No external runtime dependencies required
19
+
- 💡 **Two Operation Modes** - Optional DI for simplicity, Classic DI for advanced scenarios
- 🎯 **Type-Safe** - Full TypeScript support with decorator-based metadata
22
+
- 🔧 **Flexible Scoping** - Support for multiple isolated DI containers
23
+
- 🧪 **Test-Friendly** - Easy mocking and overriding for unit tests
24
+
- 📦 **Extensible** - Built on OOP/SOLID principles for easy customization
25
+
26
+
---
27
+
28
+
## Installation
8
29
9
30
For the latest stable version:
10
31
11
-
```Bash
32
+
```bash
12
33
npm i first-di
13
34
```
14
35
15
-
Features
16
-
------
36
+
## Quick Start
17
37
18
-
- Easy and powerful dependency injection for any TypeScript application.
19
-
- 2 modes of work. Optional DI - for most apps. Classic DI - for advanced apps.
20
-
- Support for multiple scopes.
21
-
- Supports multiple life cycles.
22
-
- Dependency-free. Dependencies are used only for development.
38
+
### Prerequisites
23
39
24
-
Setup
25
-
------
40
+
Install [reflect-metadata](https://www.npmjs.com/package/reflect-metadata) package and import it in your application entry point:
26
41
27
-
Install [reflect-metadata](https://www.npmjs.com/package/reflect-metadata) package and import it in the root TypeScript file. This package is needed to support reflection and is a mandatory requirement of TypeScript.
42
+
```bash
43
+
npm install reflect-metadata
44
+
```
28
45
29
-
In tsconfig.json enable compiler options:
46
+
Enable the following compiler options in `tsconfig.json`:
30
47
31
-
```Json
48
+
```json
32
49
{
33
50
"compilerOptions": {
34
51
...
@@ -40,10 +57,13 @@ In tsconfig.json enable compiler options:
40
57
41
58
```
42
59
43
-
Using in Optional DI mode
44
-
------
60
+
---
61
+
62
+
## Usage
63
+
64
+
### Optional DI Mode
45
65
46
-
Just write classes and inject dependencies through class constructors. When the 'resolve' function is called, all dependencies will be resolved.
66
+
The simplest approach - write classes and inject dependencies through constructors. All dependencies are automatically resolved when calling `resolve()`.
@@ -109,10 +129,9 @@ if (process.env.NODE_ENV === "test") {
109
129
}
110
130
```
111
131
112
-
Using in Classic DI mode
113
-
------
132
+
### Classic DI Mode
114
133
115
-
In professional mode Abstract classes are used instead of interfaces. TypeScript does not generate interfaces for working in runtime. Abstract classes serve as the abstract base class. So instead of interfaces, you need to write Abstract classes.
134
+
For advanced scenarios, use abstract classes as contracts instead of interfaces. Abstract classes generate runtime metadata that TypeScript interfaces cannot provide.
First DI uses OOP and SOLID design principles. Each part of DI can be overridden or extended after inheritance from the base class.
287
+
### Extending the DI Container
288
+
289
+
Built on OOP and SOLID principles, every component can be extended or customized:
267
290
268
291
```typescript
269
292
import { DI } from"first-di";
@@ -275,3 +298,13 @@ class MyDI extends DI {
275
298
}
276
299
}
277
300
```
301
+
302
+
---
303
+
304
+
## Contributing
305
+
306
+
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md) before submitting pull requests.
We actively support the following versions of `first-di` with security updates:
6
+
7
+
| Version | Supported |
8
+
| ------- | ------------------ |
9
+
| 3.x |:white_check_mark:|
10
+
| 2.x |:x:|
11
+
| < 2.0 |:x:|
12
+
13
+
## Reporting a Vulnerability
14
+
15
+
We take the security of `first-di` seriously. If you discover a security vulnerability, please follow these steps:
16
+
17
+
### How to Report
18
+
19
+
1.**DO NOT** open a public GitHub issue for security vulnerabilities
20
+
2. Send a detailed report to the repository maintainer via:
21
+
- GitHub Security Advisory: [Report a vulnerability](https://github.com/LabEG/first-di/security/advisories/new)
22
+
- Email: Create an issue in the [issue tracker](https://github.com/LabEG/first-di/issues) marked as **Security** (if no sensitive details need to be shared)
23
+
24
+
### What to Include
25
+
26
+
Please provide the following information in your report:
27
+
28
+
-**Description**: A clear description of the vulnerability
29
+
-**Impact**: What could an attacker accomplish by exploiting this vulnerability
30
+
-**Reproduction**: Step-by-step instructions to reproduce the issue
0 commit comments