node-dependency-injection 3.0.0-alpha.11 → 3.0.0-alpha.12
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 +34 -0
- package/dist/lib/Autowire.js +10 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,6 +68,39 @@ And get services from your container
|
|
|
68
68
|
const mailer = container.get('service.mailer')
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
Autowire for typescript
|
|
72
|
+
------------
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import {ContainerBuilder, Autowire} from 'node-dependency-injection'
|
|
76
|
+
|
|
77
|
+
const container = new ContainerBuilder(
|
|
78
|
+
true,
|
|
79
|
+
'/path/to/src'
|
|
80
|
+
)
|
|
81
|
+
const autowire = new Autowire(container)
|
|
82
|
+
await autowire.process()
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
or from yaml-json-js configuration
|
|
87
|
+
|
|
88
|
+
```yaml
|
|
89
|
+
# /path/to/services.yml
|
|
90
|
+
services:
|
|
91
|
+
_defaults:
|
|
92
|
+
autowire: true
|
|
93
|
+
rootDir: "/path/to/src"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
You can also get a service from a class definition
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import SomeService from '@src/service/SomeService'
|
|
100
|
+
|
|
101
|
+
container.get(SomeService)
|
|
102
|
+
```
|
|
103
|
+
|
|
71
104
|
|
|
72
105
|
Configuration files: how to load and use configuration files
|
|
73
106
|
------------
|
|
@@ -103,6 +136,7 @@ const mailer = container.get('service.mailer')
|
|
|
103
136
|
List of features
|
|
104
137
|
------------
|
|
105
138
|
|
|
139
|
+
- Autowire only for TypeScript
|
|
106
140
|
- Configuration files with JS, YAML or JSON.
|
|
107
141
|
- Multiple configuration files
|
|
108
142
|
- Custom relative service directory
|
package/dist/lib/Autowire.js
CHANGED
|
@@ -155,16 +155,19 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
155
155
|
|
|
156
156
|
if (parsedFile.ext === '.ts') {
|
|
157
157
|
_this$_getClassDeclar = this._getClassDeclaration(filePath), classDeclaration = _this$_getClassDeclar.classDeclaration, body = _this$_getClassDeclar.body;
|
|
158
|
-
Class = require(filePath)["default"];
|
|
159
158
|
|
|
160
|
-
if (
|
|
161
|
-
|
|
159
|
+
if (classDeclaration) {
|
|
160
|
+
Class = require(filePath)["default"];
|
|
162
161
|
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
this.container.setDefinition(serviceId, definition);
|
|
162
|
+
if (Class) {
|
|
163
|
+
definition = this._getDefinition(classDeclaration, body, parsedFile, Class);
|
|
166
164
|
|
|
167
|
-
|
|
165
|
+
if (definition) {
|
|
166
|
+
serviceId = this._getServiceIdFromPath(filePath, Class.name);
|
|
167
|
+
this.container.setDefinition(serviceId, definition);
|
|
168
|
+
|
|
169
|
+
this._interfaceImplementations(classDeclaration, body, parsedFile, serviceId);
|
|
170
|
+
}
|
|
168
171
|
}
|
|
169
172
|
}
|
|
170
173
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-dependency-injection",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.12",
|
|
4
4
|
"description": "The NodeDependencyInjection component allows you to standardize and centralize the way objects are constructed in your application.",
|
|
5
5
|
"main": "dist/lib/index.js",
|
|
6
6
|
"directories": {
|