inversify 4.9.0 → 4.13.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/CODE_OF_CONDUCT.md +46 -46
- package/LICENSE +22 -22
- package/README.md +306 -306
- package/amd/annotation/inject.js +14 -1
- package/amd/constants/error_msgs.js +15 -2
- package/amd/container/container.js +138 -63
- package/amd/container/container_module.js +8 -0
- package/amd/inversify.js +2 -0
- package/amd/planning/planner.js +7 -0
- package/amd/planning/reflection_utils.js +6 -7
- package/appveyor.yml +34 -34
- package/dts/annotation/inject.d.ts +7 -1
- package/dts/constants/error_msgs.d.ts +3 -2
- package/dts/container/container.d.ts +3 -1
- package/dts/container/container_module.d.ts +6 -2
- package/dts/interfaces/interfaces.d.ts +7 -0
- package/dts/inversify.d.ts +2 -2
- package/dts/planning/reflection_utils.d.ts +3 -1
- package/es/annotation/inject.js +14 -0
- package/es/constants/error_msgs.js +15 -2
- package/es/container/container.js +138 -63
- package/es/container/container_module.js +8 -0
- package/es/inversify.js +2 -2
- package/es/planning/planner.js +8 -1
- package/es/planning/reflection_utils.js +5 -7
- package/lib/annotation/inject.js +14 -0
- package/lib/constants/error_msgs.js +15 -2
- package/lib/container/container.js +138 -63
- package/lib/container/container_module.js +8 -0
- package/lib/inversify.js +2 -0
- package/lib/planning/planner.js +7 -0
- package/lib/planning/reflection_utils.js +6 -6
- package/package.json +80 -80
package/amd/annotation/inject.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
define(["require", "exports", "../constants/metadata_keys", "../planning/metadata", "./decorator_utils"], function (require, exports, METADATA_KEY, metadata_1, decorator_utils_1) {
|
|
1
|
+
define(["require", "exports", "../constants/error_msgs", "../constants/metadata_keys", "../planning/metadata", "./decorator_utils"], function (require, exports, error_msgs_1, METADATA_KEY, metadata_1, decorator_utils_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
var LazyServiceIdentifer = (function () {
|
|
5
|
+
function LazyServiceIdentifer(cb) {
|
|
6
|
+
this._cb = cb;
|
|
7
|
+
}
|
|
8
|
+
LazyServiceIdentifer.prototype.unwrap = function () {
|
|
9
|
+
return this._cb();
|
|
10
|
+
};
|
|
11
|
+
return LazyServiceIdentifer;
|
|
12
|
+
}());
|
|
13
|
+
exports.LazyServiceIdentifer = LazyServiceIdentifer;
|
|
4
14
|
function inject(serviceIdentifier) {
|
|
5
15
|
return function (target, targetKey, index) {
|
|
16
|
+
if (serviceIdentifier === undefined) {
|
|
17
|
+
throw new Error(error_msgs_1.UNDEFINED_INJECT_ANNOTATION(target.name));
|
|
18
|
+
}
|
|
6
19
|
var metadata = new metadata_1.Metadata(METADATA_KEY.INJECT_TAG, serviceIdentifier);
|
|
7
20
|
if (typeof index === "number") {
|
|
8
21
|
decorator_utils_1.tagParameter(target, targetKey, index, metadata);
|
|
@@ -10,6 +10,11 @@ define(["require", "exports"], function (require, exports) {
|
|
|
10
10
|
exports.NOT_REGISTERED = "No matching bindings found for serviceIdentifier:";
|
|
11
11
|
exports.MISSING_INJECTABLE_ANNOTATION = "Missing required @injectable annotation in:";
|
|
12
12
|
exports.MISSING_INJECT_ANNOTATION = "Missing required @inject or @multiInject annotation in:";
|
|
13
|
+
exports.UNDEFINED_INJECT_ANNOTATION = function (name) {
|
|
14
|
+
return "@inject called with undefined this could mean that the class " + name + " has " +
|
|
15
|
+
"a circular dependency problem. You can use a LazyServiceIdentifer to " +
|
|
16
|
+
"overcome this limitation.";
|
|
17
|
+
};
|
|
13
18
|
exports.CIRCULAR_DEPENDENCY = "Circular dependency found:";
|
|
14
19
|
exports.NOT_IMPLEMENTED = "Sorry, this feature is not fully implemented yet.";
|
|
15
20
|
exports.INVALID_BINDING_TYPE = "Invalid binding type:";
|
|
@@ -20,14 +25,22 @@ define(["require", "exports"], function (require, exports) {
|
|
|
20
25
|
"used as service identifier";
|
|
21
26
|
exports.INVALID_DECORATOR_OPERATION = "The @inject @multiInject @tagged and @named decorators " +
|
|
22
27
|
"must be applied to the parameters of a class constructor or a class property.";
|
|
23
|
-
exports.
|
|
24
|
-
|
|
28
|
+
exports.ARGUMENTS_LENGTH_MISMATCH = function () {
|
|
29
|
+
var values = [];
|
|
30
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
31
|
+
values[_i] = arguments[_i];
|
|
32
|
+
}
|
|
33
|
+
return "The number of constructor arguments in the derived class " +
|
|
34
|
+
(values[0] + " must be >= than the number of constructor arguments of its base class.");
|
|
35
|
+
};
|
|
25
36
|
exports.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = "Invalid Container constructor argument. Container options " +
|
|
26
37
|
"must be an object.";
|
|
27
38
|
exports.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = "Invalid Container option. Default scope must " +
|
|
28
39
|
"be a string ('singleton' or 'transient').";
|
|
29
40
|
exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = "Invalid Container option. Auto bind injectable must " +
|
|
30
41
|
"be a boolean";
|
|
42
|
+
exports.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = "Invalid Container option. Skip base check must " +
|
|
43
|
+
"be a boolean";
|
|
31
44
|
exports.MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
|
|
32
45
|
exports.POST_CONSTRUCT_ERROR = function () {
|
|
33
46
|
var values = [];
|
|
@@ -1,35 +1,72 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
3
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
4
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
5
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
6
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
10
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
11
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
12
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
13
|
+
function step(op) {
|
|
14
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
15
|
+
while (_) try {
|
|
16
|
+
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
|
17
|
+
if (y = 0, t) op = [0, t.value];
|
|
18
|
+
switch (op[0]) {
|
|
19
|
+
case 0: case 1: t = op; break;
|
|
20
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
21
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
22
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
23
|
+
default:
|
|
24
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
25
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
26
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
27
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
28
|
+
if (t[2]) _.ops.pop();
|
|
29
|
+
_.trys.pop(); continue;
|
|
30
|
+
}
|
|
31
|
+
op = body.call(thisArg, _);
|
|
32
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
33
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
1
36
|
define(["require", "exports", "../bindings/binding", "../constants/error_msgs", "../constants/literal_types", "../constants/metadata_keys", "../planning/metadata_reader", "../planning/planner", "../resolution/resolver", "../syntax/binding_to_syntax", "../utils/guid", "../utils/serialization", "./container_snapshot", "./lookup"], function (require, exports, binding_1, ERROR_MSGS, literal_types_1, METADATA_KEY, metadata_reader_1, planner_1, resolver_1, binding_to_syntax_1, guid_1, serialization_1, container_snapshot_1, lookup_1) {
|
|
2
37
|
"use strict";
|
|
3
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
39
|
var Container = (function () {
|
|
5
40
|
function Container(containerOptions) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
if (containerOptions.defaultScope !== undefined &&
|
|
12
|
-
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
|
|
13
|
-
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
|
|
14
|
-
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
|
|
15
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
16
|
-
}
|
|
17
|
-
if (containerOptions.autoBindInjectable !== undefined &&
|
|
18
|
-
typeof containerOptions.autoBindInjectable !== "boolean") {
|
|
19
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
this.options = {
|
|
23
|
-
autoBindInjectable: containerOptions.autoBindInjectable,
|
|
24
|
-
defaultScope: containerOptions.defaultScope
|
|
25
|
-
};
|
|
41
|
+
var options = containerOptions || {};
|
|
42
|
+
if (typeof options !== "object") {
|
|
43
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
|
|
26
44
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
if (options.defaultScope === undefined) {
|
|
46
|
+
options.defaultScope = literal_types_1.BindingScopeEnum.Transient;
|
|
47
|
+
}
|
|
48
|
+
else if (options.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
|
|
49
|
+
options.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
|
|
50
|
+
options.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
|
|
51
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
52
|
+
}
|
|
53
|
+
if (options.autoBindInjectable === undefined) {
|
|
54
|
+
options.autoBindInjectable = false;
|
|
32
55
|
}
|
|
56
|
+
else if (typeof options.autoBindInjectable !== "boolean") {
|
|
57
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
58
|
+
}
|
|
59
|
+
if (options.skipBaseClassChecks === undefined) {
|
|
60
|
+
options.skipBaseClassChecks = false;
|
|
61
|
+
}
|
|
62
|
+
else if (typeof options.skipBaseClassChecks !== "boolean") {
|
|
63
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK);
|
|
64
|
+
}
|
|
65
|
+
this.options = {
|
|
66
|
+
autoBindInjectable: options.autoBindInjectable,
|
|
67
|
+
defaultScope: options.defaultScope,
|
|
68
|
+
skipBaseClassChecks: options.skipBaseClassChecks
|
|
69
|
+
};
|
|
33
70
|
this.guid = guid_1.guid();
|
|
34
71
|
this._bindingDictionary = new lookup_1.Lookup();
|
|
35
72
|
this._snapshots = [];
|
|
@@ -54,46 +91,44 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
|
|
|
54
91
|
return container;
|
|
55
92
|
};
|
|
56
93
|
Container.prototype.load = function () {
|
|
57
|
-
var _this = this;
|
|
58
94
|
var modules = [];
|
|
59
95
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
60
96
|
modules[_i] = arguments[_i];
|
|
61
97
|
}
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
module.registry(bindFunction, unbindFunction, isboundFunction, rebindFunction);
|
|
98
|
+
var getHelpers = this._getContainerModuleHelpersFactory();
|
|
99
|
+
for (var _a = 0, modules_1 = modules; _a < modules_1.length; _a++) {
|
|
100
|
+
var currentModule = modules_1[_a];
|
|
101
|
+
var containerModuleHelpers = getHelpers(currentModule.guid);
|
|
102
|
+
currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
Container.prototype.loadAsync = function () {
|
|
106
|
+
var modules = [];
|
|
107
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
108
|
+
modules[_i] = arguments[_i];
|
|
109
|
+
}
|
|
110
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
111
|
+
var getHelpers, _a, modules_2, currentModule, containerModuleHelpers;
|
|
112
|
+
return __generator(this, function (_b) {
|
|
113
|
+
switch (_b.label) {
|
|
114
|
+
case 0:
|
|
115
|
+
getHelpers = this._getContainerModuleHelpersFactory();
|
|
116
|
+
_a = 0, modules_2 = modules;
|
|
117
|
+
_b.label = 1;
|
|
118
|
+
case 1:
|
|
119
|
+
if (!(_a < modules_2.length)) return [3, 4];
|
|
120
|
+
currentModule = modules_2[_a];
|
|
121
|
+
containerModuleHelpers = getHelpers(currentModule.guid);
|
|
122
|
+
return [4, currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction)];
|
|
123
|
+
case 2:
|
|
124
|
+
_b.sent();
|
|
125
|
+
_b.label = 3;
|
|
126
|
+
case 3:
|
|
127
|
+
_a++;
|
|
128
|
+
return [3, 1];
|
|
129
|
+
case 4: return [2];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
97
132
|
});
|
|
98
133
|
};
|
|
99
134
|
Container.prototype.unload = function () {
|
|
@@ -164,8 +199,8 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
|
|
|
164
199
|
this._bindingDictionary = snapshot.bindings;
|
|
165
200
|
this._middleware = snapshot.middleware;
|
|
166
201
|
};
|
|
167
|
-
Container.prototype.createChild = function () {
|
|
168
|
-
var child = new Container();
|
|
202
|
+
Container.prototype.createChild = function (containerOptions) {
|
|
203
|
+
var child = new Container(containerOptions);
|
|
169
204
|
child.parent = this;
|
|
170
205
|
return child;
|
|
171
206
|
};
|
|
@@ -204,6 +239,46 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
|
|
|
204
239
|
tempContainer.parent = this;
|
|
205
240
|
return tempContainer.get(constructorFunction);
|
|
206
241
|
};
|
|
242
|
+
Container.prototype._getContainerModuleHelpersFactory = function () {
|
|
243
|
+
var _this = this;
|
|
244
|
+
var setModuleId = function (bindingToSyntax, moduleId) {
|
|
245
|
+
bindingToSyntax._binding.moduleId = moduleId;
|
|
246
|
+
};
|
|
247
|
+
var getBindFunction = function (moduleId) {
|
|
248
|
+
return function (serviceIdentifier) {
|
|
249
|
+
var _bind = _this.bind.bind(_this);
|
|
250
|
+
var bindingToSyntax = _bind(serviceIdentifier);
|
|
251
|
+
setModuleId(bindingToSyntax, moduleId);
|
|
252
|
+
return bindingToSyntax;
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
var getUnbindFunction = function (moduleId) {
|
|
256
|
+
return function (serviceIdentifier) {
|
|
257
|
+
var _unbind = _this.unbind.bind(_this);
|
|
258
|
+
_unbind(serviceIdentifier);
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
var getIsboundFunction = function (moduleId) {
|
|
262
|
+
return function (serviceIdentifier) {
|
|
263
|
+
var _isBound = _this.isBound.bind(_this);
|
|
264
|
+
return _isBound(serviceIdentifier);
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
var getRebindFunction = function (moduleId) {
|
|
268
|
+
return function (serviceIdentifier) {
|
|
269
|
+
var _rebind = _this.rebind.bind(_this);
|
|
270
|
+
var bindingToSyntax = _rebind(serviceIdentifier);
|
|
271
|
+
setModuleId(bindingToSyntax, moduleId);
|
|
272
|
+
return bindingToSyntax;
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
return function (mId) { return ({
|
|
276
|
+
bindFunction: getBindFunction(mId),
|
|
277
|
+
isboundFunction: getIsboundFunction(mId),
|
|
278
|
+
rebindFunction: getRebindFunction(mId),
|
|
279
|
+
unbindFunction: getUnbindFunction(mId)
|
|
280
|
+
}); };
|
|
281
|
+
};
|
|
207
282
|
Container.prototype._get = function (avoidConstraints, isMultiInject, targetType, serviceIdentifier, key, value) {
|
|
208
283
|
var result = null;
|
|
209
284
|
var defaultArgs = {
|
|
@@ -9,4 +9,12 @@ define(["require", "exports", "../utils/guid"], function (require, exports, guid
|
|
|
9
9
|
return ContainerModule;
|
|
10
10
|
}());
|
|
11
11
|
exports.ContainerModule = ContainerModule;
|
|
12
|
+
var AsyncContainerModule = (function () {
|
|
13
|
+
function AsyncContainerModule(registry) {
|
|
14
|
+
this.guid = guid_1.guid();
|
|
15
|
+
this.registry = registry;
|
|
16
|
+
}
|
|
17
|
+
return AsyncContainerModule;
|
|
18
|
+
}());
|
|
19
|
+
exports.AsyncContainerModule = AsyncContainerModule;
|
|
12
20
|
});
|
package/amd/inversify.js
CHANGED
|
@@ -6,11 +6,13 @@ define(["require", "exports", "./constants/metadata_keys", "./container/containe
|
|
|
6
6
|
exports.BindingScopeEnum = literal_types_1.BindingScopeEnum;
|
|
7
7
|
exports.BindingTypeEnum = literal_types_1.BindingTypeEnum;
|
|
8
8
|
exports.TargetTypeEnum = literal_types_1.TargetTypeEnum;
|
|
9
|
+
exports.AsyncContainerModule = container_module_1.AsyncContainerModule;
|
|
9
10
|
exports.ContainerModule = container_module_1.ContainerModule;
|
|
10
11
|
exports.injectable = injectable_1.injectable;
|
|
11
12
|
exports.tagged = tagged_1.tagged;
|
|
12
13
|
exports.named = named_1.named;
|
|
13
14
|
exports.inject = inject_1.inject;
|
|
15
|
+
exports.LazyServiceIdentifer = inject_1.LazyServiceIdentifer;
|
|
14
16
|
exports.optional = optional_1.optional;
|
|
15
17
|
exports.unmanaged = unmanaged_1.unmanaged;
|
|
16
18
|
exports.multiInject = multi_inject_1.multiInject;
|
package/amd/planning/planner.js
CHANGED
|
@@ -93,6 +93,13 @@ define(["require", "exports", "../bindings/binding_count", "../constants/error_m
|
|
|
93
93
|
}
|
|
94
94
|
if (binding.type === literal_types_1.BindingTypeEnum.Instance && binding.implementationType !== null) {
|
|
95
95
|
var dependencies = reflection_utils_1.getDependencies(metadataReader, binding.implementationType);
|
|
96
|
+
if (!context.container.options.skipBaseClassChecks) {
|
|
97
|
+
var baseClassDependencyCount = reflection_utils_1.getBaseClassDependencyCount(metadataReader, binding.implementationType);
|
|
98
|
+
if (dependencies.length < baseClassDependencyCount) {
|
|
99
|
+
var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH(reflection_utils_1.getFunctionName(binding.implementationType));
|
|
100
|
+
throw new Error(error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
96
103
|
dependencies.forEach(function (dependency) {
|
|
97
104
|
_createSubRequests(metadataReader, false, dependency.serviceIdentifier, context, subChildRequest, dependency);
|
|
98
105
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
define(["require", "exports", "../constants/error_msgs", "../constants/literal_types", "../constants/metadata_keys", "../utils/serialization", "./target"], function (require, exports, ERROR_MSGS, literal_types_1, METADATA_KEY, serialization_1, target_1) {
|
|
1
|
+
define(["require", "exports", "../annotation/inject", "../constants/error_msgs", "../constants/literal_types", "../constants/metadata_keys", "../utils/serialization", "./target"], function (require, exports, inject_1, ERROR_MSGS, literal_types_1, METADATA_KEY, serialization_1, target_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getFunctionName = serialization_1.getFunctionName;
|
|
4
5
|
function getDependencies(metadataReader, func) {
|
|
5
6
|
var constructorName = serialization_1.getFunctionName(func);
|
|
6
7
|
var targets = getTargets(metadataReader, constructorName, func, false);
|
|
@@ -21,12 +22,6 @@ define(["require", "exports", "../constants/error_msgs", "../constants/literal_t
|
|
|
21
22
|
var constructorTargets = getConstructorArgsAsTargets(isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata, iterations);
|
|
22
23
|
var propertyTargets = getClassPropsAsTargets(metadataReader, func);
|
|
23
24
|
var targets = constructorTargets.concat(propertyTargets);
|
|
24
|
-
var baseClassDependencyCount = getBaseClassDependencyCount(metadataReader, func);
|
|
25
|
-
if (targets.length < baseClassDependencyCount) {
|
|
26
|
-
var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_1 +
|
|
27
|
-
constructorName + ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_2;
|
|
28
|
-
throw new Error(error);
|
|
29
|
-
}
|
|
30
25
|
return targets;
|
|
31
26
|
}
|
|
32
27
|
function getConstructorArgsAsTarget(index, isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata) {
|
|
@@ -36,6 +31,9 @@ define(["require", "exports", "../constants/error_msgs", "../constants/literal_t
|
|
|
36
31
|
var serviceIdentifier = serviceIdentifiers[index];
|
|
37
32
|
var injectIdentifier = (metadata.inject || metadata.multiInject);
|
|
38
33
|
serviceIdentifier = (injectIdentifier) ? (injectIdentifier) : serviceIdentifier;
|
|
34
|
+
if (serviceIdentifier instanceof inject_1.LazyServiceIdentifer) {
|
|
35
|
+
serviceIdentifier = serviceIdentifier.unwrap();
|
|
36
|
+
}
|
|
39
37
|
if (isManaged) {
|
|
40
38
|
var isObject = serviceIdentifier === Object;
|
|
41
39
|
var isFunction = serviceIdentifier === Function;
|
|
@@ -106,6 +104,7 @@ define(["require", "exports", "../constants/error_msgs", "../constants/literal_t
|
|
|
106
104
|
return 0;
|
|
107
105
|
}
|
|
108
106
|
}
|
|
107
|
+
exports.getBaseClassDependencyCount = getBaseClassDependencyCount;
|
|
109
108
|
function formatTargetMetadata(targetMetadata) {
|
|
110
109
|
var targetMetadataMap = {};
|
|
111
110
|
targetMetadata.forEach(function (m) {
|
package/appveyor.yml
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
# AppVeyor file
|
|
2
|
-
# http://www.appveyor.com/docs/appveyor-yml
|
|
3
|
-
|
|
4
|
-
# Build version format
|
|
5
|
-
version: "{build}"
|
|
6
|
-
|
|
7
|
-
# Test against this version of Node.js
|
|
8
|
-
environment:
|
|
9
|
-
NODE_ENV: test
|
|
10
|
-
|
|
11
|
-
matrix:
|
|
12
|
-
- nodejs_version: "9.3.0"
|
|
13
|
-
|
|
14
|
-
build: off
|
|
15
|
-
|
|
16
|
-
branches:
|
|
17
|
-
only:
|
|
18
|
-
- master
|
|
19
|
-
|
|
20
|
-
install:
|
|
21
|
-
- ps: Install-Product node $env:nodejs_version
|
|
22
|
-
- npm install -g npm
|
|
23
|
-
- npm config set progress=false
|
|
24
|
-
- npm install
|
|
25
|
-
|
|
26
|
-
# Fix line endings on Windows
|
|
27
|
-
init:
|
|
28
|
-
- git config --global core.autocrlf true
|
|
29
|
-
|
|
30
|
-
test_script:
|
|
31
|
-
# Output useful info for debugging.
|
|
32
|
-
- node --version && npm --version
|
|
33
|
-
- ps: "npm --version # PowerShell" # Pass comment to PS for easier debugging
|
|
34
|
-
- cmd: npm run test
|
|
1
|
+
# AppVeyor file
|
|
2
|
+
# http://www.appveyor.com/docs/appveyor-yml
|
|
3
|
+
|
|
4
|
+
# Build version format
|
|
5
|
+
version: "{build}"
|
|
6
|
+
|
|
7
|
+
# Test against this version of Node.js
|
|
8
|
+
environment:
|
|
9
|
+
NODE_ENV: test
|
|
10
|
+
|
|
11
|
+
matrix:
|
|
12
|
+
- nodejs_version: "9.3.0"
|
|
13
|
+
|
|
14
|
+
build: off
|
|
15
|
+
|
|
16
|
+
branches:
|
|
17
|
+
only:
|
|
18
|
+
- master
|
|
19
|
+
|
|
20
|
+
install:
|
|
21
|
+
- ps: Install-Product node $env:nodejs_version
|
|
22
|
+
- npm install -g npm
|
|
23
|
+
- npm config set progress=false
|
|
24
|
+
- npm install
|
|
25
|
+
|
|
26
|
+
# Fix line endings on Windows
|
|
27
|
+
init:
|
|
28
|
+
- git config --global core.autocrlf true
|
|
29
|
+
|
|
30
|
+
test_script:
|
|
31
|
+
# Output useful info for debugging.
|
|
32
|
+
- node --version && npm --version
|
|
33
|
+
- ps: "npm --version # PowerShell" # Pass comment to PS for easier debugging
|
|
34
|
+
- cmd: npm run test
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { interfaces } from "../interfaces/interfaces";
|
|
2
|
-
declare
|
|
2
|
+
export declare type ServiceIdentifierOrFunc = interfaces.ServiceIdentifier<any> | LazyServiceIdentifer;
|
|
3
|
+
export declare class LazyServiceIdentifer<T = any> {
|
|
4
|
+
private _cb;
|
|
5
|
+
constructor(cb: () => interfaces.ServiceIdentifier<T>);
|
|
6
|
+
unwrap(): string | symbol | interfaces.Newable<T> | interfaces.Abstract<T>;
|
|
7
|
+
}
|
|
8
|
+
declare function inject(serviceIdentifier: ServiceIdentifierOrFunc): (target: any, targetKey: string, index?: number | undefined) => void;
|
|
3
9
|
export { inject };
|
|
@@ -7,6 +7,7 @@ export declare const CANNOT_UNBIND = "Could not unbind serviceIdentifier:";
|
|
|
7
7
|
export declare const NOT_REGISTERED = "No matching bindings found for serviceIdentifier:";
|
|
8
8
|
export declare const MISSING_INJECTABLE_ANNOTATION = "Missing required @injectable annotation in:";
|
|
9
9
|
export declare const MISSING_INJECT_ANNOTATION = "Missing required @inject or @multiInject annotation in:";
|
|
10
|
+
export declare const UNDEFINED_INJECT_ANNOTATION: (name: string) => string;
|
|
10
11
|
export declare const CIRCULAR_DEPENDENCY = "Circular dependency found:";
|
|
11
12
|
export declare const NOT_IMPLEMENTED = "Sorry, this feature is not fully implemented yet.";
|
|
12
13
|
export declare const INVALID_BINDING_TYPE = "Invalid binding type:";
|
|
@@ -15,11 +16,11 @@ export declare const INVALID_MIDDLEWARE_RETURN = "Invalid return type in middlew
|
|
|
15
16
|
export declare const INVALID_FUNCTION_BINDING = "Value provided to function binding must be a function!";
|
|
16
17
|
export declare const INVALID_TO_SELF_VALUE: string;
|
|
17
18
|
export declare const INVALID_DECORATOR_OPERATION: string;
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const ARGUMENTS_LENGTH_MISMATCH_2 = " must be >= than the number of constructor arguments of its base class.";
|
|
19
|
+
export declare const ARGUMENTS_LENGTH_MISMATCH: (...values: any[]) => string;
|
|
20
20
|
export declare const CONTAINER_OPTIONS_MUST_BE_AN_OBJECT: string;
|
|
21
21
|
export declare const CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE: string;
|
|
22
22
|
export declare const CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE: string;
|
|
23
|
+
export declare const CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK: string;
|
|
23
24
|
export declare const MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
|
|
24
25
|
export declare const POST_CONSTRUCT_ERROR: (...values: any[]) => string;
|
|
25
26
|
export declare const CIRCULAR_DEPENDENCY_IN_FACTORY: (...values: any[]) => string;
|
|
@@ -10,6 +10,7 @@ declare class Container implements interfaces.Container {
|
|
|
10
10
|
static merge(container1: interfaces.Container, container2: interfaces.Container): interfaces.Container;
|
|
11
11
|
constructor(containerOptions?: interfaces.ContainerOptions);
|
|
12
12
|
load(...modules: interfaces.ContainerModule[]): void;
|
|
13
|
+
loadAsync(...modules: interfaces.AsyncContainerModule[]): Promise<void>;
|
|
13
14
|
unload(...modules: interfaces.ContainerModule[]): void;
|
|
14
15
|
bind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T>;
|
|
15
16
|
rebind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T>;
|
|
@@ -20,7 +21,7 @@ declare class Container implements interfaces.Container {
|
|
|
20
21
|
isBoundTagged(serviceIdentifier: interfaces.ServiceIdentifier<any>, key: string | number | symbol, value: any): boolean;
|
|
21
22
|
snapshot(): void;
|
|
22
23
|
restore(): void;
|
|
23
|
-
createChild(): Container;
|
|
24
|
+
createChild(containerOptions?: interfaces.ContainerOptions): Container;
|
|
24
25
|
applyMiddleware(...middlewares: interfaces.Middleware[]): void;
|
|
25
26
|
applyCustomMetadataReader(metadataReader: interfaces.MetadataReader): void;
|
|
26
27
|
get<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T;
|
|
@@ -30,6 +31,7 @@ declare class Container implements interfaces.Container {
|
|
|
30
31
|
getAllTagged<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: any): T[];
|
|
31
32
|
getAllNamed<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): T[];
|
|
32
33
|
resolve<T>(constructorFunction: interfaces.Newable<T>): T;
|
|
34
|
+
private _getContainerModuleHelpersFactory();
|
|
33
35
|
private _get<T>(avoidConstraints, isMultiInject, targetType, serviceIdentifier, key?, value?);
|
|
34
36
|
private _planAndResolve<T>();
|
|
35
37
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { interfaces } from "../interfaces/interfaces";
|
|
2
|
-
declare class ContainerModule implements interfaces.ContainerModule {
|
|
2
|
+
export declare class ContainerModule implements interfaces.ContainerModule {
|
|
3
3
|
guid: string;
|
|
4
4
|
registry: interfaces.ContainerModuleCallBack;
|
|
5
5
|
constructor(registry: interfaces.ContainerModuleCallBack);
|
|
6
6
|
}
|
|
7
|
-
export
|
|
7
|
+
export declare class AsyncContainerModule implements interfaces.AsyncContainerModule {
|
|
8
|
+
guid: string;
|
|
9
|
+
registry: interfaces.AsyncContainerModuleCallBack;
|
|
10
|
+
constructor(registry: interfaces.AsyncContainerModuleCallBack);
|
|
11
|
+
}
|
|
@@ -122,6 +122,7 @@ declare namespace interfaces {
|
|
|
122
122
|
interface ContainerOptions {
|
|
123
123
|
autoBindInjectable?: boolean;
|
|
124
124
|
defaultScope?: BindingScope;
|
|
125
|
+
skipBaseClassChecks?: boolean;
|
|
125
126
|
}
|
|
126
127
|
interface Container {
|
|
127
128
|
guid: string;
|
|
@@ -140,6 +141,7 @@ declare namespace interfaces {
|
|
|
140
141
|
getAll<T>(serviceIdentifier: ServiceIdentifier<T>): T[];
|
|
141
142
|
resolve<T>(constructorFunction: interfaces.Newable<T>): T;
|
|
142
143
|
load(...modules: ContainerModule[]): void;
|
|
144
|
+
loadAsync(...modules: AsyncContainerModule[]): Promise<void>;
|
|
143
145
|
unload(...modules: ContainerModule[]): void;
|
|
144
146
|
applyCustomMetadataReader(metadataReader: MetadataReader): void;
|
|
145
147
|
applyMiddleware(...middleware: Middleware[]): void;
|
|
@@ -155,7 +157,12 @@ declare namespace interfaces {
|
|
|
155
157
|
guid: string;
|
|
156
158
|
registry: ContainerModuleCallBack;
|
|
157
159
|
}
|
|
160
|
+
interface AsyncContainerModule {
|
|
161
|
+
guid: string;
|
|
162
|
+
registry: AsyncContainerModuleCallBack;
|
|
163
|
+
}
|
|
158
164
|
type ContainerModuleCallBack = (bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => void;
|
|
165
|
+
type AsyncContainerModuleCallBack = (bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => Promise<void>;
|
|
159
166
|
interface ContainerSnapshot {
|
|
160
167
|
bindings: Lookup<Binding<any>>;
|
|
161
168
|
middleware: Next | null;
|
package/dts/inversify.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import * as keys from "./constants/metadata_keys";
|
|
|
2
2
|
export declare const METADATA_KEY: typeof keys;
|
|
3
3
|
export { Container } from "./container/container";
|
|
4
4
|
export { BindingScopeEnum, BindingTypeEnum, TargetTypeEnum } from "./constants/literal_types";
|
|
5
|
-
export { ContainerModule } from "./container/container_module";
|
|
5
|
+
export { AsyncContainerModule, ContainerModule } from "./container/container_module";
|
|
6
6
|
export { injectable } from "./annotation/injectable";
|
|
7
7
|
export { tagged } from "./annotation/tagged";
|
|
8
8
|
export { named } from "./annotation/named";
|
|
9
|
-
export { inject } from "./annotation/inject";
|
|
9
|
+
export { inject, LazyServiceIdentifer } from "./annotation/inject";
|
|
10
10
|
export { optional } from "./annotation/optional";
|
|
11
11
|
export { unmanaged } from "./annotation/unmanaged";
|
|
12
12
|
export { multiInject } from "./annotation/multi_inject";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { interfaces } from "../interfaces/interfaces";
|
|
2
|
+
import { getFunctionName } from "../utils/serialization";
|
|
2
3
|
declare function getDependencies(metadataReader: interfaces.MetadataReader, func: Function): interfaces.Target[];
|
|
3
|
-
|
|
4
|
+
declare function getBaseClassDependencyCount(metadataReader: interfaces.MetadataReader, func: Function): number;
|
|
5
|
+
export { getDependencies, getBaseClassDependencyCount, getFunctionName };
|
package/es/annotation/inject.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
|
+
import { UNDEFINED_INJECT_ANNOTATION } from "../constants/error_msgs";
|
|
1
2
|
import * as METADATA_KEY from "../constants/metadata_keys";
|
|
2
3
|
import { Metadata } from "../planning/metadata";
|
|
3
4
|
import { tagParameter, tagProperty } from "./decorator_utils";
|
|
5
|
+
var LazyServiceIdentifer = (function () {
|
|
6
|
+
function LazyServiceIdentifer(cb) {
|
|
7
|
+
this._cb = cb;
|
|
8
|
+
}
|
|
9
|
+
LazyServiceIdentifer.prototype.unwrap = function () {
|
|
10
|
+
return this._cb();
|
|
11
|
+
};
|
|
12
|
+
return LazyServiceIdentifer;
|
|
13
|
+
}());
|
|
14
|
+
export { LazyServiceIdentifer };
|
|
4
15
|
function inject(serviceIdentifier) {
|
|
5
16
|
return function (target, targetKey, index) {
|
|
17
|
+
if (serviceIdentifier === undefined) {
|
|
18
|
+
throw new Error(UNDEFINED_INJECT_ANNOTATION(target.name));
|
|
19
|
+
}
|
|
6
20
|
var metadata = new Metadata(METADATA_KEY.INJECT_TAG, serviceIdentifier);
|
|
7
21
|
if (typeof index === "number") {
|
|
8
22
|
tagParameter(target, targetKey, index, metadata);
|