@fluojs/di 1.0.0-beta.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/LICENSE +21 -0
- package/README.ko.md +155 -0
- package/README.md +155 -0
- package/dist/container.d.ts +133 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/container.js +697 -0
- package/dist/errors.d.ts +62 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +126 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/types.d.ts +144 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +98 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 fluo contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.ko.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# @fluojs/di
|
|
2
|
+
|
|
3
|
+
<p><a href="./README.md"><kbd>English</kbd></a> <strong><kbd>한국어</kbd></strong></p>
|
|
4
|
+
|
|
5
|
+
모든 fluo 애플리케이션을 구동하는 최소 토큰 기반 의존성 주입 컨테이너입니다.
|
|
6
|
+
|
|
7
|
+
## 목차
|
|
8
|
+
|
|
9
|
+
- [설치](#설치)
|
|
10
|
+
- [사용 시점](#사용-시점)
|
|
11
|
+
- [빠른 시작](#빠른-시작)
|
|
12
|
+
- [주요 기능](#주요-기능)
|
|
13
|
+
- [순환 의존성 처리](#순환-의존성-처리)
|
|
14
|
+
- [테스트 및 모킹](#테스트-및-모킹)
|
|
15
|
+
- [문제 해결](#문제-해결)
|
|
16
|
+
- [공개 API](#공개-api)
|
|
17
|
+
- [관련 패키지](#관련-패키지)
|
|
18
|
+
- [예제 소스](#예제-소스)
|
|
19
|
+
|
|
20
|
+
## 설치
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @fluojs/di
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 사용 시점
|
|
27
|
+
|
|
28
|
+
- 런타임에 클래스와 의존성을 실제 인스턴스로 해석해야 할 때
|
|
29
|
+
- singleton, request, transient 같은 수명 주기를 관리해야 할 때
|
|
30
|
+
- 테스트나 환경별 설정에서 구현체를 명시적으로 교체해야 할 때
|
|
31
|
+
- HTTP 요청이나 백그라운드 작업마다 격리된 request scope가 필요할 때
|
|
32
|
+
|
|
33
|
+
## 빠른 시작
|
|
34
|
+
|
|
35
|
+
컨테이너는 등록된 provider를 기준으로 토큰을 인스턴스로 해석합니다.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { Container } from '@fluojs/di';
|
|
39
|
+
import { Inject, Scope } from '@fluojs/core';
|
|
40
|
+
|
|
41
|
+
class Logger {
|
|
42
|
+
log(message: string) {
|
|
43
|
+
console.log(message);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Inject(Logger)
|
|
48
|
+
@Scope('singleton')
|
|
49
|
+
class UserService {
|
|
50
|
+
constructor(private readonly logger: Logger) {}
|
|
51
|
+
|
|
52
|
+
async getStatus() {
|
|
53
|
+
this.logger.log('상태 확인 중...');
|
|
54
|
+
return { status: 'active' };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const container = new Container();
|
|
59
|
+
container.register(Logger, UserService);
|
|
60
|
+
|
|
61
|
+
const service = await container.resolve(UserService);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 주요 기능
|
|
65
|
+
|
|
66
|
+
### 다양한 provider 형태 지원
|
|
67
|
+
|
|
68
|
+
- **클래스 provider**: `container.register(MyService)` 또는 `{ provide, useClass }`
|
|
69
|
+
- **값 provider**: `{ provide: 'API_URL', useValue: 'https://api.example.com' }`
|
|
70
|
+
- **팩토리 provider**: `{ provide, useFactory, inject }`
|
|
71
|
+
- **별칭(Alias) provider**: `{ provide: ILogger, useExisting: PinoLogger }`를 사용하여 하나의 토큰을 기존에 등록된 다른 provider로 매핑할 수 있습니다.
|
|
72
|
+
|
|
73
|
+
### scope-aware 수명 주기 관리
|
|
74
|
+
|
|
75
|
+
- **singleton**: 루트 컨테이너에서 한 번 생성되어 공유됩니다.
|
|
76
|
+
- **request**: `createRequestScope()`마다 새로 생성됩니다.
|
|
77
|
+
- **transient**: resolve할 때마다 새 인스턴스를 만듭니다.
|
|
78
|
+
|
|
79
|
+
### request scope 분리
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const requestContainer = container.createRequestScope();
|
|
83
|
+
const scopedService = await requestContainer.resolve(RequestScopedService);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## 순환 의존성 처리
|
|
87
|
+
|
|
88
|
+
컨테이너는 순환 의존성을 자동으로 감지하고 `CircularDependencyError`를 발생시켜 무한 루프를 방지합니다. 여기에는 직접 참조(A→A), 이중 노드(A→B→A), 깊은 순환(A→B→C→A)이 모두 포함됩니다.
|
|
89
|
+
|
|
90
|
+
순환 의존성을 해결하려면 `forwardRef()`를 사용하여 의존성 토큰의 해석을 지연시키세요.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { forwardRef } from '@fluojs/di';
|
|
94
|
+
import { Inject } from '@fluojs/core';
|
|
95
|
+
|
|
96
|
+
@Inject(forwardRef(() => ServiceB))
|
|
97
|
+
class ServiceA {
|
|
98
|
+
constructor(private serviceB: any) {}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@Inject(forwardRef(() => ServiceA))
|
|
102
|
+
class ServiceB {
|
|
103
|
+
constructor(private serviceA: any) {}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 테스트 및 모킹
|
|
108
|
+
|
|
109
|
+
`useValue`를 사용하면 단위 테스트 중에 컨테이너의 provider를 모의 객체(mock)나 스텁(stub)으로 쉽게 교체할 수 있습니다.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { Container } from '@fluojs/di';
|
|
113
|
+
|
|
114
|
+
const container = new Container();
|
|
115
|
+
const mockDb = { query: jest.fn() };
|
|
116
|
+
|
|
117
|
+
// 실제 Database 클래스를 모의 객체 값으로 교체
|
|
118
|
+
container.register({
|
|
119
|
+
provide: Database,
|
|
120
|
+
useValue: mockDb
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const service = await container.resolve(DataService);
|
|
124
|
+
// 이제 service는 실제 Database 인스턴스 대신 mockDb를 사용합니다.
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## 문제 해결
|
|
128
|
+
|
|
129
|
+
### CircularDependencyError
|
|
130
|
+
의존성 그래프에서 순환이 감지될 때 발생합니다. 생성자 주입 항목을 확인하고 필요한 경우 `forwardRef()`를 사용하여 순환을 끊으세요.
|
|
131
|
+
|
|
132
|
+
### 토큰을 찾을 수 없음 (Token Not Found)
|
|
133
|
+
필요한 모든 provider가 컨테이너에 등록되어 있는지 확인하세요. `createRequestScope()`를 사용하는 경우 자식 컨테이너는 부모의 토큰을 해석할 수 있지만, 그 반대는 불가능합니다.
|
|
134
|
+
|
|
135
|
+
## 공개 API
|
|
136
|
+
|
|
137
|
+
| 클래스/메서드 | 설명 |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `Container` | 메인 DI 컨테이너 클래스입니다. |
|
|
140
|
+
| `register(...providers)` | 하나 이상의 프로바이더를 등록합니다. |
|
|
141
|
+
| `resolve<T>(token)` | 토큰을 인스턴스로 비동기 해석합니다. |
|
|
142
|
+
| `createRequestScope()` | 요청 스코프 의존성을 위한 자식 컨테이너를 생성합니다. |
|
|
143
|
+
| `has(token)` | 컨테이너나 부모에 토큰이 등록되어 있는지 확인합니다. |
|
|
144
|
+
|
|
145
|
+
## 관련 패키지
|
|
146
|
+
|
|
147
|
+
- `@fluojs/core`: `@Inject()`와 `@Scope()` 데코레이터를 정의합니다.
|
|
148
|
+
- `@fluojs/runtime`: 부트스트랩 중 provider 등록과 모듈 그래프 조립을 담당합니다.
|
|
149
|
+
- `@fluojs/http`: 들어오는 요청마다 request scope를 생성합니다.
|
|
150
|
+
|
|
151
|
+
## 예제 소스
|
|
152
|
+
|
|
153
|
+
- `packages/di/src/container.ts`
|
|
154
|
+
- `packages/di/src/container.test.ts`
|
|
155
|
+
- `examples/minimal/src/app.ts`
|
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# @fluojs/di
|
|
2
|
+
|
|
3
|
+
<p><strong><kbd>English</kbd></strong> <a href="./README.ko.md"><kbd>한국어</kbd></a></p>
|
|
4
|
+
|
|
5
|
+
Minimal token-based dependency injection container powering every fluo application.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [When to Use](#when-to-use)
|
|
11
|
+
- [Quick Start](#quick-start)
|
|
12
|
+
- [Key Capabilities](#key-capabilities)
|
|
13
|
+
- [Circular Dependency Handling](#circular-dependency-handling)
|
|
14
|
+
- [Testing and Mocking](#testing-and-mocking)
|
|
15
|
+
- [Troubleshooting](#troubleshooting)
|
|
16
|
+
- [Public API](#public-api)
|
|
17
|
+
- [Related Packages](#related-packages)
|
|
18
|
+
- [Example Sources](#example-sources)
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @fluojs/di
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## When to Use
|
|
27
|
+
|
|
28
|
+
Use this package when you need to:
|
|
29
|
+
- Resolve classes and their dependencies at runtime.
|
|
30
|
+
- Manage object lifetimes (Singleton, Request, Transient).
|
|
31
|
+
- Override implementations for testing or environment-specific needs.
|
|
32
|
+
- Create isolated request-scoped containers for HTTP or background tasks.
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
The container resolves tokens into instances based on their registered providers.
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { Container } from '@fluojs/di';
|
|
40
|
+
import { Inject, Scope } from '@fluojs/core';
|
|
41
|
+
|
|
42
|
+
class Logger {
|
|
43
|
+
log(msg: string) { console.log(msg); }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Inject(Logger)
|
|
47
|
+
@Scope('singleton')
|
|
48
|
+
class UserService {
|
|
49
|
+
constructor(private logger: Logger) {}
|
|
50
|
+
|
|
51
|
+
async getStatus() {
|
|
52
|
+
this.logger.log('Checking status...');
|
|
53
|
+
return { status: 'active' };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const container = new Container();
|
|
58
|
+
container.register(Logger, UserService);
|
|
59
|
+
|
|
60
|
+
const service = await container.resolve(UserService);
|
|
61
|
+
const result = await service.getStatus();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Key Capabilities
|
|
65
|
+
|
|
66
|
+
### Provider Types
|
|
67
|
+
fluo DI supports three main provider shapes:
|
|
68
|
+
- **Class Providers**: `container.register(MyService)` or `{ provide: MyToken, useClass: MyService }`.
|
|
69
|
+
- **Value Providers**: `{ provide: 'API_URL', useValue: 'https://api.example.com' }`.
|
|
70
|
+
- **Factory Providers**: `{ provide: 'ASYNC_CONFIG', useFactory: async (db) => await db.load(), inject: [Database] }`.
|
|
71
|
+
- **Alias Providers**: `{ provide: ILogger, useExisting: PinoLogger }` allows mapping one token to another existing provider.
|
|
72
|
+
|
|
73
|
+
### Scope Management
|
|
74
|
+
- **Singleton** (Default): Instance is created once and shared across the entire container.
|
|
75
|
+
- **Request**: Instance is created once per `createRequestScope()` call.
|
|
76
|
+
- **Transient**: A new instance is created every time it is resolved.
|
|
77
|
+
|
|
78
|
+
### Request Scoping
|
|
79
|
+
Isolated containers can be created to handle per-request state without polluting the root container.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
const requestContainer = container.createRequestScope();
|
|
83
|
+
const scopedService = await requestContainer.resolve(RequestScopedService);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Circular Dependency Handling
|
|
87
|
+
|
|
88
|
+
The container automatically detects circular dependencies and throws a `CircularDependencyError` to prevent infinite loops. This includes direct (A→A), two-node (A→B→A), and deep (A→B→C→A) cycles.
|
|
89
|
+
|
|
90
|
+
To resolve a circular dependency, use `forwardRef()` to defer the resolution of the dependent token.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { forwardRef } from '@fluojs/di';
|
|
94
|
+
import { Inject } from '@fluojs/core';
|
|
95
|
+
|
|
96
|
+
@Inject(forwardRef(() => ServiceB))
|
|
97
|
+
class ServiceA {
|
|
98
|
+
constructor(private serviceB: any) {}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@Inject(forwardRef(() => ServiceA))
|
|
102
|
+
class ServiceB {
|
|
103
|
+
constructor(private serviceA: any) {}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Testing and Mocking
|
|
108
|
+
|
|
109
|
+
You can easily override providers in the container to use mocks or stubs during unit testing by using `useValue`.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { Container } from '@fluojs/di';
|
|
113
|
+
|
|
114
|
+
const container = new Container();
|
|
115
|
+
const mockDb = { query: jest.fn() };
|
|
116
|
+
|
|
117
|
+
// Override the real Database class with a mock value
|
|
118
|
+
container.register({
|
|
119
|
+
provide: Database,
|
|
120
|
+
useValue: mockDb
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const service = await container.resolve(DataService);
|
|
124
|
+
// service will now use mockDb instead of the real Database instance
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Troubleshooting
|
|
128
|
+
|
|
129
|
+
### CircularDependencyError
|
|
130
|
+
Thrown when the container detects a cycle in the dependency graph. Check your constructor injections and use `forwardRef()` where necessary to break the cycle.
|
|
131
|
+
|
|
132
|
+
### Token Not Found
|
|
133
|
+
Ensure all required providers are registered in the container. If you use `createRequestScope()`, the child container can resolve tokens from the parent, but not vice versa.
|
|
134
|
+
|
|
135
|
+
## Public API
|
|
136
|
+
|
|
137
|
+
| Class/Method | Description |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `Container` | The main DI container class. |
|
|
140
|
+
| `register(...providers)` | Registers one or more providers. |
|
|
141
|
+
| `resolve<T>(token)` | Asynchronously resolves a token to an instance. |
|
|
142
|
+
| `createRequestScope()` | Creates a child container for request-scoped dependencies. |
|
|
143
|
+
| `has(token)` | Checks if a token is registered in the container or its parents. |
|
|
144
|
+
|
|
145
|
+
## Related Packages
|
|
146
|
+
|
|
147
|
+
- **`@fluojs/core`**: Defines the `@Inject()` and `@Scope()` decorators used to annotate classes.
|
|
148
|
+
- **`@fluojs/runtime`**: Handles automatic registration of providers during application bootstrap.
|
|
149
|
+
- **`@fluojs/http`**: Creates a request scope for every incoming HTTP request.
|
|
150
|
+
|
|
151
|
+
## Example Sources
|
|
152
|
+
|
|
153
|
+
- `packages/di/src/container.ts`
|
|
154
|
+
- `packages/di/src/container.test.ts`
|
|
155
|
+
- `examples/minimal/src/app.ts`
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { type Token } from '@fluojs/core';
|
|
2
|
+
import type { Provider } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Scope-aware dependency injection container for Fluo providers.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Container {
|
|
7
|
+
private readonly parent?;
|
|
8
|
+
private readonly requestScopeEnabled;
|
|
9
|
+
private readonly registrations;
|
|
10
|
+
private readonly multiRegistrations;
|
|
11
|
+
private readonly multiOverriddenTokens;
|
|
12
|
+
private readonly requestCache;
|
|
13
|
+
private readonly multiRequestCache;
|
|
14
|
+
private readonly multiSingletonCache;
|
|
15
|
+
private readonly staleDisposalTasks;
|
|
16
|
+
private readonly staleDisposalErrors;
|
|
17
|
+
private readonly singletonCache;
|
|
18
|
+
private readonly childScopes;
|
|
19
|
+
private disposePromise;
|
|
20
|
+
private disposed;
|
|
21
|
+
constructor(parent?: Container | undefined, requestScopeEnabled?: boolean, singletonCache?: Map<Token, Promise<unknown>>);
|
|
22
|
+
/**
|
|
23
|
+
* Registers providers in the current container scope.
|
|
24
|
+
*
|
|
25
|
+
* @param providers Provider definitions to register in this container.
|
|
26
|
+
* @returns The same container instance for fluent registration chains.
|
|
27
|
+
* @throws {ContainerResolutionError} When called after the container was disposed.
|
|
28
|
+
* @throws {ScopeMismatchError} When registering singleton providers directly on a request scope.
|
|
29
|
+
* @throws {DuplicateProviderError} When registration conflicts with existing single/multi mappings.
|
|
30
|
+
* @throws {InvalidProviderError} When a provider definition is structurally invalid.
|
|
31
|
+
*/
|
|
32
|
+
register(...providers: Provider[]): this;
|
|
33
|
+
/**
|
|
34
|
+
* Override one or more already-registered providers.
|
|
35
|
+
*
|
|
36
|
+
* **Multi-provider destructive replacement**: when the incoming provider has `multi: true`,
|
|
37
|
+
* the entire existing multi-registration array for that token is deleted before the new entry
|
|
38
|
+
* is added. There is intentionally no way to replace a single entry within a multi-provider
|
|
39
|
+
* set — the whole set is replaced. If you need to preserve other entries, re-register them
|
|
40
|
+
* together with the replacement in one `override()` call.
|
|
41
|
+
*
|
|
42
|
+
* @param providers Provider definitions that should replace existing registrations for each token.
|
|
43
|
+
* @returns The same container instance for fluent override chains.
|
|
44
|
+
* @throws {ContainerResolutionError} When called after the container was disposed.
|
|
45
|
+
* @throws {InvalidProviderError} When a provider definition is structurally invalid.
|
|
46
|
+
*/
|
|
47
|
+
override(...providers: Provider[]): this;
|
|
48
|
+
/**
|
|
49
|
+
* Returns whether a token is registered in this scope chain.
|
|
50
|
+
*
|
|
51
|
+
* @param token Token to check across this container and its ancestors.
|
|
52
|
+
* @returns `true` when a single or multi provider exists for the token.
|
|
53
|
+
*/
|
|
54
|
+
has(token: Token): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a child request-scope container that shares root singleton cache.
|
|
57
|
+
*
|
|
58
|
+
* @returns A request-scope child container bound to this container hierarchy.
|
|
59
|
+
* @throws {ContainerResolutionError} When called after the container was disposed.
|
|
60
|
+
*/
|
|
61
|
+
createRequestScope(): Container;
|
|
62
|
+
/**
|
|
63
|
+
* Resolves a token to an instance using scope-aware caching rules.
|
|
64
|
+
*
|
|
65
|
+
* @param token Token to resolve.
|
|
66
|
+
* @returns A promise that resolves to the token instance (or multi-provider instance array).
|
|
67
|
+
* @throws {ContainerResolutionError} When called after disposal or when no provider is registered.
|
|
68
|
+
* @throws {RequestScopeResolutionError} When request-scoped providers are resolved from root scope.
|
|
69
|
+
* @throws {ScopeMismatchError} When singleton providers depend on request-scoped providers.
|
|
70
|
+
* @throws {CircularDependencyError} When provider dependency resolution detects a cycle.
|
|
71
|
+
*/
|
|
72
|
+
resolve<T>(token: Token<T>): Promise<T>;
|
|
73
|
+
/**
|
|
74
|
+
* Disposes cached instances and nested request scopes.
|
|
75
|
+
*
|
|
76
|
+
* @returns A promise that settles after all cached disposable instances are torn down.
|
|
77
|
+
* @throws {Error} Propagates one or more disposal errors (`AggregateError` when multiple failures occur).
|
|
78
|
+
*/
|
|
79
|
+
dispose(): Promise<void>;
|
|
80
|
+
private disposeAll;
|
|
81
|
+
private hasMulti;
|
|
82
|
+
private assertNoRegistrationConflict;
|
|
83
|
+
private hasAncestorSingleRegistration;
|
|
84
|
+
private hasSingleRegistration;
|
|
85
|
+
private hasAncestorMultiRegistration;
|
|
86
|
+
private hasMultiRegistration;
|
|
87
|
+
private collectMultiProviders;
|
|
88
|
+
private resolveWithChain;
|
|
89
|
+
private resolveFromRegisteredProviders;
|
|
90
|
+
private requireProvider;
|
|
91
|
+
private resolveAliasTarget;
|
|
92
|
+
private resolveForwardRefCircularDependency;
|
|
93
|
+
private resolveMultiProviderInstances;
|
|
94
|
+
private resolveMultiProviderInstance;
|
|
95
|
+
private resolveExistingProviderTarget;
|
|
96
|
+
private resolveScopedOrSingletonInstance;
|
|
97
|
+
private shouldResolveFromRoot;
|
|
98
|
+
private shouldResolveMultiProviderFromRoot;
|
|
99
|
+
private resolveDepToken;
|
|
100
|
+
private withTokenInChain;
|
|
101
|
+
private root;
|
|
102
|
+
private lookupProvider;
|
|
103
|
+
/**
|
|
104
|
+
* Resolve the cache map that should hold the instance for `provider`.
|
|
105
|
+
*
|
|
106
|
+
* **Singleton-in-request-scope**: if a provider with `scope: 'singleton'` (the default) is
|
|
107
|
+
* registered directly on a request-scope child container (rather than the root), it is cached
|
|
108
|
+
* in the child's `requestCache` instead of the root's `singletonCache`. This means it behaves
|
|
109
|
+
* as request-scoped despite the singleton scope annotation. This is intentional — it allows
|
|
110
|
+
* test and override scenarios to inject short-lived values without polluting the global cache
|
|
111
|
+
* — but the divergence from the declared scope is a known footgun for consumers who
|
|
112
|
+
* inadvertently register singletons on child containers.
|
|
113
|
+
*/
|
|
114
|
+
private cacheFor;
|
|
115
|
+
private multiCacheFor;
|
|
116
|
+
private hasLocalMultiProvider;
|
|
117
|
+
private disposalCacheEntries;
|
|
118
|
+
private disposeCache;
|
|
119
|
+
private collectDisposableInstances;
|
|
120
|
+
private disposeInstancesInReverseOrder;
|
|
121
|
+
private clearDisposalCaches;
|
|
122
|
+
private waitForStaleDisposalTasks;
|
|
123
|
+
private scheduleStaleDisposal;
|
|
124
|
+
private throwDisposalErrors;
|
|
125
|
+
private isDisposable;
|
|
126
|
+
private instantiate;
|
|
127
|
+
private assertSingletonDependencyScopes;
|
|
128
|
+
private resolveEffectiveProvider;
|
|
129
|
+
private resolveProviderDependencyToken;
|
|
130
|
+
private resolveProviderDeps;
|
|
131
|
+
private invalidateCachedEntry;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAW3E,OAAO,KAAK,EASV,QAAQ,EAET,MAAM,YAAY,CAAC;AA8FpB;;GAEG;AACH,qBAAa,SAAS;IAelB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IAftC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAwC;IACtE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA0C;IAC7E,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAoB;IAC1D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsC;IACnE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmD;IACrF,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAmD;IACvF,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA4B;IAC/D,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAiB;IACrD,OAAO,CAAC,QAA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