ts-ioc-container 23.3.2 → 23.3.4
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 +6 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ yarn add ts-ioc-container reflect-metadata
|
|
|
27
27
|
|
|
28
28
|
## Setup
|
|
29
29
|
### reflect-metadata
|
|
30
|
-
Just put it in the main file of your project. It should be first line of the code.
|
|
30
|
+
Just put it in the main file of your project. It should be the first line of the code.
|
|
31
31
|
```typescript
|
|
32
32
|
import 'reflect-metadata';
|
|
33
33
|
```
|
|
@@ -64,7 +64,7 @@ class App {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
const container = new Container(new ReflectionInjector()).register('ILogger', Provider.fromClass(Logger));
|
|
67
|
-
container.resolve(App).
|
|
67
|
+
container.resolve(App).logger.name === 'Logger'; // true
|
|
68
68
|
|
|
69
69
|
container.dispose();
|
|
70
70
|
```
|
|
@@ -72,7 +72,8 @@ container.dispose();
|
|
|
72
72
|
### Scopes
|
|
73
73
|
Sometimes you need to create a scope of container. For example, when you want to create a scope per request in web application.
|
|
74
74
|
|
|
75
|
-
- NOTICE:
|
|
75
|
+
- NOTICE: remember that when scope doesn't have dependency then it will be resolved from parent container
|
|
76
|
+
- NOTICE: when you create a scope of container then all providers are cloned to new scope. For that reason every provider has methods `clone` and `isValid` to clone itself and check if it's valid for certain scope accordingly.
|
|
76
77
|
|
|
77
78
|
```typescript
|
|
78
79
|
import { Container, ReflectionInjector } from "ts-ioc-container";
|
|
@@ -82,9 +83,9 @@ const scope = container.createScope();
|
|
|
82
83
|
```
|
|
83
84
|
|
|
84
85
|
### Tags
|
|
85
|
-
Sometimes you want to mark some providers and resolve them only from certain scope.
|
|
86
|
+
Sometimes you want to mark some providers and resolve them only from certain scope. So you can assign tags to providers and create scopes with certain tags. For that reason every scope has method `hasTag` which we invoke from provider to check if it's valid for certain scope.
|
|
86
87
|
|
|
87
|
-
- tag - is a string that
|
|
88
|
+
- tag - is a string that we assign to provider and scope/container
|
|
88
89
|
- every provider can be registered per certain tags and cannot be resolved from container with other tags. Only from parent one with certain tags.
|
|
89
90
|
- NOTICE: when you create a scope then we clone ONLY tags-matched providers.
|
|
90
91
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ioc-container",
|
|
3
|
-
"version": "23.3.
|
|
3
|
+
"version": "23.3.4",
|
|
4
4
|
"description": "Typescript IoC container",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"ts-jest": "27.0.5",
|
|
53
53
|
"typescript": "4.4.3"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "62bde181e5286f8d43611f8b740ed3e230bb4768"
|
|
56
56
|
}
|