@resolid/di 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/dist/index.d.ts +4 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TypeScript Dependency Injection Container
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|

|
|
5
5
|
|
|
6
6
|
<b>[Documentation](https://www.resolid.tech/docs/di)</b> | [Framework Bundle](https://github.com/resolid/framework)
|
|
7
7
|
|
|
8
|
-
## TypeScript Dependency Injection Container
|
|
9
|
-
|
|
10
8
|
A lightweight, fully-typed Dependency Injection (DI) container for TypeScript.
|
|
11
9
|
Supports singleton & transient scopes, lazy resolution, optional dependencies, and disposable resources. Fully functional with async factories
|
|
12
10
|
and avoids circular dependency issues.
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
## Features
|
|
15
13
|
|
|
16
14
|
- Fully typed with TypeScript, no any.
|
|
17
15
|
- Supports singleton and transient scopes.
|
|
@@ -22,7 +20,7 @@ and avoids circular dependency issues.
|
|
|
22
20
|
- Fully async-compatible with inject() and injectAsync() functions.
|
|
23
21
|
- Context-aware injection with InjectionContext.
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
## Installation
|
|
26
24
|
|
|
27
25
|
```shell
|
|
28
26
|
pnpm add @resolid/di
|
|
@@ -34,7 +32,9 @@ yarn add @resolid/di
|
|
|
34
32
|
bun add @resolid/di
|
|
35
33
|
```
|
|
36
34
|
|
|
37
|
-
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
### Basic
|
|
38
38
|
|
|
39
39
|
```typescript
|
|
40
40
|
import { Container, inject } from "@resolid/di";
|
|
@@ -102,13 +102,13 @@ import { Container, injectAsync } from "@resolid/di";
|
|
|
102
102
|
|
|
103
103
|
class AsyncDatabaseService {
|
|
104
104
|
async connect(): Promise<void> {
|
|
105
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
105
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
106
106
|
console.log("Database connected");
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
class AsyncUserService {
|
|
111
|
-
private db
|
|
111
|
+
private db: AsyncDatabaseService;
|
|
112
112
|
|
|
113
113
|
constructor(db: AsyncDatabaseService) {
|
|
114
114
|
this.db = db;
|
|
@@ -135,7 +135,7 @@ container.add({
|
|
|
135
135
|
token: AsyncUserService,
|
|
136
136
|
factory: async () => {
|
|
137
137
|
const db = await injectAsync(AsyncDatabaseService);
|
|
138
|
-
return new AsyncUserService(db)
|
|
138
|
+
return new AsyncUserService(db);
|
|
139
139
|
},
|
|
140
140
|
async: true,
|
|
141
141
|
});
|
|
@@ -153,7 +153,7 @@ console.log(user); // Output: User 1
|
|
|
153
153
|
import { Container, inject } from "@resolid/di";
|
|
154
154
|
|
|
155
155
|
class AnalyticsService {
|
|
156
|
-
private logger?: LogService
|
|
156
|
+
private logger?: LogService;
|
|
157
157
|
|
|
158
158
|
constructor(logger?: LogService) {
|
|
159
159
|
this.logger = logger;
|
|
@@ -186,7 +186,7 @@ analytics.track("page_view"); // Output: Analytics (no logger): page_view
|
|
|
186
186
|
import { Container, inject } from "@resolid/di";
|
|
187
187
|
|
|
188
188
|
class ReportService {
|
|
189
|
-
private getLogger
|
|
189
|
+
private getLogger: () => LogService;
|
|
190
190
|
|
|
191
191
|
constructor(private getLogger: () => LogService) {
|
|
192
192
|
this.getLogger = getLogger;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
//#region src/shared/index.d.ts
|
|
2
|
-
type
|
|
3
|
-
|
|
2
|
+
type Token<T = unknown> = symbol | (new (...args: any[]) => T) | {
|
|
3
|
+
prototype: T;
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
4
6
|
interface Disposable {
|
|
5
7
|
dispose: () => Promise<void> | void;
|
|
6
8
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@resolid/di",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "TypeScript Dependency Injection Container",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"resolid",
|
|
8
8
|
"container",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@vitest/coverage-v8": "^4.0.
|
|
40
|
-
"tsdown": "^0.15.
|
|
39
|
+
"@vitest/coverage-v8": "^4.0.4",
|
|
40
|
+
"tsdown": "^0.15.11",
|
|
41
41
|
"typescript": "^5.9.3",
|
|
42
|
-
"vitest": "^4.0.
|
|
42
|
+
"vitest": "^4.0.4"
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": "^20.19.0 || ^22.13.0 || >=24"
|