@travetto/di 3.0.0-rc.8 → 3.0.0
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 +5 -1
- package/package.json +3 -3
- package/support/main.invoke.ts +0 -17
package/README.md
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
**Install: @travetto/di**
|
|
7
7
|
```bash
|
|
8
8
|
npm install @travetto/di
|
|
9
|
+
|
|
10
|
+
# or
|
|
11
|
+
|
|
12
|
+
yarn add @travetto/di
|
|
9
13
|
```
|
|
10
14
|
|
|
11
15
|
[Dependency injection](https://en.wikipedia.org/wiki/Dependency_injection) is a framework primitive. When used in conjunction with automatic file scanning, it provides for handling of application dependency wiring. Due to the nature of [Typescript](https://typescriptlang.org) and type erasure of interfaces, dependency injection only supports `class`es as a type signifier. The primary goal of dependency injection is to allow for separation of concerns of object creation and it's usage.
|
|
@@ -93,7 +97,7 @@ class Config {
|
|
|
93
97
|
|
|
94
98
|
Given the `static` method `initService`, the function will be provided as a valid candidate for `CoolService`. Instead of calling the constructor of the type directly, this function will work as a factory for producing the injectable.
|
|
95
99
|
|
|
96
|
-
**Note**: Other modules are able to provide aliases to [@Injectable](https://github.com/travetto/travetto/tree/main/module/di/src/decorator.ts#L31) that also provide additional functionality. For example, the [
|
|
100
|
+
**Note**: Other modules are able to provide aliases to [@Injectable](https://github.com/travetto/travetto/tree/main/module/di/src/decorator.ts#L31) that also provide additional functionality. For example, the [Configuration](https://github.com/travetto/travetto/tree/main/module/config#readme "Configuration support") module @Config or the [RESTful API](https://github.com/travetto/travetto/tree/main/module/rest#readme "Declarative api for RESTful APIs with support for the dependency injection module.") module @Controller decorator registers the associated class as an injectable element.
|
|
97
101
|
|
|
98
102
|
## Injection
|
|
99
103
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/di",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Dependency registration/management and injection support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast-transformations",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"directory": "module/di"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/registry": "^3.0.0
|
|
30
|
+
"@travetto/registry": "^3.0.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@travetto/transformer": "^3.0.0
|
|
33
|
+
"@travetto/transformer": "^3.0.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependenciesMeta": {
|
|
36
36
|
"@travetto/transformer": {
|
package/support/main.invoke.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { RootRegistry } from '@travetto/registry';
|
|
2
|
-
|
|
3
|
-
import { DependencyRegistry } from '../src/registry';
|
|
4
|
-
|
|
5
|
-
export async function main(...[mod, cls, method, qualifier]: (string | undefined)[]): Promise<unknown> {
|
|
6
|
-
await RootRegistry.init();
|
|
7
|
-
|
|
8
|
-
const tgt = (await import(mod!))[cls!];
|
|
9
|
-
|
|
10
|
-
const inst = await DependencyRegistry.getInstance(
|
|
11
|
-
tgt,
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
13
|
-
qualifier ? Symbol.for(qualifier) : qualifier as undefined
|
|
14
|
-
);
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
16
|
-
return await (inst as Record<string, () => Promise<unknown>>)[method!]();
|
|
17
|
-
}
|