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
|
@@ -7,6 +7,11 @@ export var CANNOT_UNBIND = "Could not unbind serviceIdentifier:";
|
|
|
7
7
|
export var NOT_REGISTERED = "No matching bindings found for serviceIdentifier:";
|
|
8
8
|
export var MISSING_INJECTABLE_ANNOTATION = "Missing required @injectable annotation in:";
|
|
9
9
|
export var MISSING_INJECT_ANNOTATION = "Missing required @inject or @multiInject annotation in:";
|
|
10
|
+
export var UNDEFINED_INJECT_ANNOTATION = function (name) {
|
|
11
|
+
return "@inject called with undefined this could mean that the class " + name + " has " +
|
|
12
|
+
"a circular dependency problem. You can use a LazyServiceIdentifer to " +
|
|
13
|
+
"overcome this limitation.";
|
|
14
|
+
};
|
|
10
15
|
export var CIRCULAR_DEPENDENCY = "Circular dependency found:";
|
|
11
16
|
export var NOT_IMPLEMENTED = "Sorry, this feature is not fully implemented yet.";
|
|
12
17
|
export var INVALID_BINDING_TYPE = "Invalid binding type:";
|
|
@@ -17,14 +22,22 @@ export var INVALID_TO_SELF_VALUE = "The toSelf function can only be applied when
|
|
|
17
22
|
"used as service identifier";
|
|
18
23
|
export var INVALID_DECORATOR_OPERATION = "The @inject @multiInject @tagged and @named decorators " +
|
|
19
24
|
"must be applied to the parameters of a class constructor or a class property.";
|
|
20
|
-
export var
|
|
21
|
-
|
|
25
|
+
export var ARGUMENTS_LENGTH_MISMATCH = function () {
|
|
26
|
+
var values = [];
|
|
27
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
28
|
+
values[_i] = arguments[_i];
|
|
29
|
+
}
|
|
30
|
+
return "The number of constructor arguments in the derived class " +
|
|
31
|
+
(values[0] + " must be >= than the number of constructor arguments of its base class.");
|
|
32
|
+
};
|
|
22
33
|
export var CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = "Invalid Container constructor argument. Container options " +
|
|
23
34
|
"must be an object.";
|
|
24
35
|
export var CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = "Invalid Container option. Default scope must " +
|
|
25
36
|
"be a string ('singleton' or 'transient').";
|
|
26
37
|
export var CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = "Invalid Container option. Auto bind injectable must " +
|
|
27
38
|
"be a boolean";
|
|
39
|
+
export var CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = "Invalid Container option. Skip base check must " +
|
|
40
|
+
"be a boolean";
|
|
28
41
|
export var MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
|
|
29
42
|
export var POST_CONSTRUCT_ERROR = function () {
|
|
30
43
|
var values = [];
|
|
@@ -1,3 +1,38 @@
|
|
|
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
|
import { Binding } from "../bindings/binding";
|
|
2
37
|
import * as ERROR_MSGS from "../constants/error_msgs";
|
|
3
38
|
import { BindingScopeEnum, TargetTypeEnum } from "../constants/literal_types";
|
|
@@ -12,33 +47,35 @@ import { ContainerSnapshot } from "./container_snapshot";
|
|
|
12
47
|
import { Lookup } from "./lookup";
|
|
13
48
|
var Container = (function () {
|
|
14
49
|
function Container(containerOptions) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
if (containerOptions.defaultScope !== undefined &&
|
|
21
|
-
containerOptions.defaultScope !== BindingScopeEnum.Singleton &&
|
|
22
|
-
containerOptions.defaultScope !== BindingScopeEnum.Transient &&
|
|
23
|
-
containerOptions.defaultScope !== BindingScopeEnum.Request) {
|
|
24
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
25
|
-
}
|
|
26
|
-
if (containerOptions.autoBindInjectable !== undefined &&
|
|
27
|
-
typeof containerOptions.autoBindInjectable !== "boolean") {
|
|
28
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
this.options = {
|
|
32
|
-
autoBindInjectable: containerOptions.autoBindInjectable,
|
|
33
|
-
defaultScope: containerOptions.defaultScope
|
|
34
|
-
};
|
|
50
|
+
var options = containerOptions || {};
|
|
51
|
+
if (typeof options !== "object") {
|
|
52
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
|
|
35
53
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
54
|
+
if (options.defaultScope === undefined) {
|
|
55
|
+
options.defaultScope = BindingScopeEnum.Transient;
|
|
56
|
+
}
|
|
57
|
+
else if (options.defaultScope !== BindingScopeEnum.Singleton &&
|
|
58
|
+
options.defaultScope !== BindingScopeEnum.Transient &&
|
|
59
|
+
options.defaultScope !== BindingScopeEnum.Request) {
|
|
60
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
61
|
+
}
|
|
62
|
+
if (options.autoBindInjectable === undefined) {
|
|
63
|
+
options.autoBindInjectable = false;
|
|
41
64
|
}
|
|
65
|
+
else if (typeof options.autoBindInjectable !== "boolean") {
|
|
66
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
67
|
+
}
|
|
68
|
+
if (options.skipBaseClassChecks === undefined) {
|
|
69
|
+
options.skipBaseClassChecks = false;
|
|
70
|
+
}
|
|
71
|
+
else if (typeof options.skipBaseClassChecks !== "boolean") {
|
|
72
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK);
|
|
73
|
+
}
|
|
74
|
+
this.options = {
|
|
75
|
+
autoBindInjectable: options.autoBindInjectable,
|
|
76
|
+
defaultScope: options.defaultScope,
|
|
77
|
+
skipBaseClassChecks: options.skipBaseClassChecks
|
|
78
|
+
};
|
|
42
79
|
this.guid = guid();
|
|
43
80
|
this._bindingDictionary = new Lookup();
|
|
44
81
|
this._snapshots = [];
|
|
@@ -63,46 +100,44 @@ var Container = (function () {
|
|
|
63
100
|
return container;
|
|
64
101
|
};
|
|
65
102
|
Container.prototype.load = function () {
|
|
66
|
-
var _this = this;
|
|
67
103
|
var modules = [];
|
|
68
104
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
69
105
|
modules[_i] = arguments[_i];
|
|
70
106
|
}
|
|
71
|
-
var
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
module.registry(bindFunction, unbindFunction, isboundFunction, rebindFunction);
|
|
107
|
+
var getHelpers = this._getContainerModuleHelpersFactory();
|
|
108
|
+
for (var _a = 0, modules_1 = modules; _a < modules_1.length; _a++) {
|
|
109
|
+
var currentModule = modules_1[_a];
|
|
110
|
+
var containerModuleHelpers = getHelpers(currentModule.guid);
|
|
111
|
+
currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
Container.prototype.loadAsync = function () {
|
|
115
|
+
var modules = [];
|
|
116
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
117
|
+
modules[_i] = arguments[_i];
|
|
118
|
+
}
|
|
119
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
+
var getHelpers, _a, modules_2, currentModule, containerModuleHelpers;
|
|
121
|
+
return __generator(this, function (_b) {
|
|
122
|
+
switch (_b.label) {
|
|
123
|
+
case 0:
|
|
124
|
+
getHelpers = this._getContainerModuleHelpersFactory();
|
|
125
|
+
_a = 0, modules_2 = modules;
|
|
126
|
+
_b.label = 1;
|
|
127
|
+
case 1:
|
|
128
|
+
if (!(_a < modules_2.length)) return [3, 4];
|
|
129
|
+
currentModule = modules_2[_a];
|
|
130
|
+
containerModuleHelpers = getHelpers(currentModule.guid);
|
|
131
|
+
return [4, currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction)];
|
|
132
|
+
case 2:
|
|
133
|
+
_b.sent();
|
|
134
|
+
_b.label = 3;
|
|
135
|
+
case 3:
|
|
136
|
+
_a++;
|
|
137
|
+
return [3, 1];
|
|
138
|
+
case 4: return [2];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
106
141
|
});
|
|
107
142
|
};
|
|
108
143
|
Container.prototype.unload = function () {
|
|
@@ -173,8 +208,8 @@ var Container = (function () {
|
|
|
173
208
|
this._bindingDictionary = snapshot.bindings;
|
|
174
209
|
this._middleware = snapshot.middleware;
|
|
175
210
|
};
|
|
176
|
-
Container.prototype.createChild = function () {
|
|
177
|
-
var child = new Container();
|
|
211
|
+
Container.prototype.createChild = function (containerOptions) {
|
|
212
|
+
var child = new Container(containerOptions);
|
|
178
213
|
child.parent = this;
|
|
179
214
|
return child;
|
|
180
215
|
};
|
|
@@ -213,6 +248,46 @@ var Container = (function () {
|
|
|
213
248
|
tempContainer.parent = this;
|
|
214
249
|
return tempContainer.get(constructorFunction);
|
|
215
250
|
};
|
|
251
|
+
Container.prototype._getContainerModuleHelpersFactory = function () {
|
|
252
|
+
var _this = this;
|
|
253
|
+
var setModuleId = function (bindingToSyntax, moduleId) {
|
|
254
|
+
bindingToSyntax._binding.moduleId = moduleId;
|
|
255
|
+
};
|
|
256
|
+
var getBindFunction = function (moduleId) {
|
|
257
|
+
return function (serviceIdentifier) {
|
|
258
|
+
var _bind = _this.bind.bind(_this);
|
|
259
|
+
var bindingToSyntax = _bind(serviceIdentifier);
|
|
260
|
+
setModuleId(bindingToSyntax, moduleId);
|
|
261
|
+
return bindingToSyntax;
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
var getUnbindFunction = function (moduleId) {
|
|
265
|
+
return function (serviceIdentifier) {
|
|
266
|
+
var _unbind = _this.unbind.bind(_this);
|
|
267
|
+
_unbind(serviceIdentifier);
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
var getIsboundFunction = function (moduleId) {
|
|
271
|
+
return function (serviceIdentifier) {
|
|
272
|
+
var _isBound = _this.isBound.bind(_this);
|
|
273
|
+
return _isBound(serviceIdentifier);
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
var getRebindFunction = function (moduleId) {
|
|
277
|
+
return function (serviceIdentifier) {
|
|
278
|
+
var _rebind = _this.rebind.bind(_this);
|
|
279
|
+
var bindingToSyntax = _rebind(serviceIdentifier);
|
|
280
|
+
setModuleId(bindingToSyntax, moduleId);
|
|
281
|
+
return bindingToSyntax;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
return function (mId) { return ({
|
|
285
|
+
bindFunction: getBindFunction(mId),
|
|
286
|
+
isboundFunction: getIsboundFunction(mId),
|
|
287
|
+
rebindFunction: getRebindFunction(mId),
|
|
288
|
+
unbindFunction: getUnbindFunction(mId)
|
|
289
|
+
}); };
|
|
290
|
+
};
|
|
216
291
|
Container.prototype._get = function (avoidConstraints, isMultiInject, targetType, serviceIdentifier, key, value) {
|
|
217
292
|
var result = null;
|
|
218
293
|
var defaultArgs = {
|
|
@@ -7,3 +7,11 @@ var ContainerModule = (function () {
|
|
|
7
7
|
return ContainerModule;
|
|
8
8
|
}());
|
|
9
9
|
export { ContainerModule };
|
|
10
|
+
var AsyncContainerModule = (function () {
|
|
11
|
+
function AsyncContainerModule(registry) {
|
|
12
|
+
this.guid = guid();
|
|
13
|
+
this.registry = registry;
|
|
14
|
+
}
|
|
15
|
+
return AsyncContainerModule;
|
|
16
|
+
}());
|
|
17
|
+
export { AsyncContainerModule };
|
package/es/inversify.js
CHANGED
|
@@ -2,11 +2,11 @@ import * as keys from "./constants/metadata_keys";
|
|
|
2
2
|
export var METADATA_KEY = 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";
|
package/es/planning/planner.js
CHANGED
|
@@ -7,7 +7,7 @@ import { circularDependencyToException, getServiceIdentifierAsString, listMetada
|
|
|
7
7
|
import { Context } from "./context";
|
|
8
8
|
import { Metadata } from "./metadata";
|
|
9
9
|
import { Plan } from "./plan";
|
|
10
|
-
import { getDependencies } from "./reflection_utils";
|
|
10
|
+
import { getBaseClassDependencyCount, getDependencies, getFunctionName } from "./reflection_utils";
|
|
11
11
|
import { Request } from "./request";
|
|
12
12
|
import { Target } from "./target";
|
|
13
13
|
function getBindingDictionary(cntnr) {
|
|
@@ -101,6 +101,13 @@ function _createSubRequests(metadataReader, avoidConstraints, serviceIdentifier,
|
|
|
101
101
|
}
|
|
102
102
|
if (binding.type === BindingTypeEnum.Instance && binding.implementationType !== null) {
|
|
103
103
|
var dependencies = getDependencies(metadataReader, binding.implementationType);
|
|
104
|
+
if (!context.container.options.skipBaseClassChecks) {
|
|
105
|
+
var baseClassDependencyCount = getBaseClassDependencyCount(metadataReader, binding.implementationType);
|
|
106
|
+
if (dependencies.length < baseClassDependencyCount) {
|
|
107
|
+
var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH(getFunctionName(binding.implementationType));
|
|
108
|
+
throw new Error(error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
104
111
|
dependencies.forEach(function (dependency) {
|
|
105
112
|
_createSubRequests(metadataReader, false, dependency.serviceIdentifier, context, subChildRequest, dependency);
|
|
106
113
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LazyServiceIdentifer } from "../annotation/inject";
|
|
1
2
|
import * as ERROR_MSGS from "../constants/error_msgs";
|
|
2
3
|
import { TargetTypeEnum } from "../constants/literal_types";
|
|
3
4
|
import * as METADATA_KEY from "../constants/metadata_keys";
|
|
@@ -22,12 +23,6 @@ function getTargets(metadataReader, constructorName, func, isBaseClass) {
|
|
|
22
23
|
var constructorTargets = getConstructorArgsAsTargets(isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata, iterations);
|
|
23
24
|
var propertyTargets = getClassPropsAsTargets(metadataReader, func);
|
|
24
25
|
var targets = constructorTargets.concat(propertyTargets);
|
|
25
|
-
var baseClassDependencyCount = getBaseClassDependencyCount(metadataReader, func);
|
|
26
|
-
if (targets.length < baseClassDependencyCount) {
|
|
27
|
-
var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_1 +
|
|
28
|
-
constructorName + ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_2;
|
|
29
|
-
throw new Error(error);
|
|
30
|
-
}
|
|
31
26
|
return targets;
|
|
32
27
|
}
|
|
33
28
|
function getConstructorArgsAsTarget(index, isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata) {
|
|
@@ -37,6 +32,9 @@ function getConstructorArgsAsTarget(index, isBaseClass, constructorName, service
|
|
|
37
32
|
var serviceIdentifier = serviceIdentifiers[index];
|
|
38
33
|
var injectIdentifier = (metadata.inject || metadata.multiInject);
|
|
39
34
|
serviceIdentifier = (injectIdentifier) ? (injectIdentifier) : serviceIdentifier;
|
|
35
|
+
if (serviceIdentifier instanceof LazyServiceIdentifer) {
|
|
36
|
+
serviceIdentifier = serviceIdentifier.unwrap();
|
|
37
|
+
}
|
|
40
38
|
if (isManaged) {
|
|
41
39
|
var isObject = serviceIdentifier === Object;
|
|
42
40
|
var isFunction = serviceIdentifier === Function;
|
|
@@ -119,4 +117,4 @@ function formatTargetMetadata(targetMetadata) {
|
|
|
119
117
|
unmanaged: targetMetadataMap[METADATA_KEY.UNMANAGED_TAG]
|
|
120
118
|
};
|
|
121
119
|
}
|
|
122
|
-
export { getDependencies };
|
|
120
|
+
export { getDependencies, getBaseClassDependencyCount, getFunctionName };
|
package/lib/annotation/inject.js
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var error_msgs_1 = require("../constants/error_msgs");
|
|
3
4
|
var METADATA_KEY = require("../constants/metadata_keys");
|
|
4
5
|
var metadata_1 = require("../planning/metadata");
|
|
5
6
|
var decorator_utils_1 = require("./decorator_utils");
|
|
7
|
+
var LazyServiceIdentifer = (function () {
|
|
8
|
+
function LazyServiceIdentifer(cb) {
|
|
9
|
+
this._cb = cb;
|
|
10
|
+
}
|
|
11
|
+
LazyServiceIdentifer.prototype.unwrap = function () {
|
|
12
|
+
return this._cb();
|
|
13
|
+
};
|
|
14
|
+
return LazyServiceIdentifer;
|
|
15
|
+
}());
|
|
16
|
+
exports.LazyServiceIdentifer = LazyServiceIdentifer;
|
|
6
17
|
function inject(serviceIdentifier) {
|
|
7
18
|
return function (target, targetKey, index) {
|
|
19
|
+
if (serviceIdentifier === undefined) {
|
|
20
|
+
throw new Error(error_msgs_1.UNDEFINED_INJECT_ANNOTATION(target.name));
|
|
21
|
+
}
|
|
8
22
|
var metadata = new metadata_1.Metadata(METADATA_KEY.INJECT_TAG, serviceIdentifier);
|
|
9
23
|
if (typeof index === "number") {
|
|
10
24
|
decorator_utils_1.tagParameter(target, targetKey, index, metadata);
|
|
@@ -9,6 +9,11 @@ exports.CANNOT_UNBIND = "Could not unbind serviceIdentifier:";
|
|
|
9
9
|
exports.NOT_REGISTERED = "No matching bindings found for serviceIdentifier:";
|
|
10
10
|
exports.MISSING_INJECTABLE_ANNOTATION = "Missing required @injectable annotation in:";
|
|
11
11
|
exports.MISSING_INJECT_ANNOTATION = "Missing required @inject or @multiInject annotation in:";
|
|
12
|
+
exports.UNDEFINED_INJECT_ANNOTATION = function (name) {
|
|
13
|
+
return "@inject called with undefined this could mean that the class " + name + " has " +
|
|
14
|
+
"a circular dependency problem. You can use a LazyServiceIdentifer to " +
|
|
15
|
+
"overcome this limitation.";
|
|
16
|
+
};
|
|
12
17
|
exports.CIRCULAR_DEPENDENCY = "Circular dependency found:";
|
|
13
18
|
exports.NOT_IMPLEMENTED = "Sorry, this feature is not fully implemented yet.";
|
|
14
19
|
exports.INVALID_BINDING_TYPE = "Invalid binding type:";
|
|
@@ -19,14 +24,22 @@ exports.INVALID_TO_SELF_VALUE = "The toSelf function can only be applied when a
|
|
|
19
24
|
"used as service identifier";
|
|
20
25
|
exports.INVALID_DECORATOR_OPERATION = "The @inject @multiInject @tagged and @named decorators " +
|
|
21
26
|
"must be applied to the parameters of a class constructor or a class property.";
|
|
22
|
-
exports.
|
|
23
|
-
|
|
27
|
+
exports.ARGUMENTS_LENGTH_MISMATCH = function () {
|
|
28
|
+
var values = [];
|
|
29
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
30
|
+
values[_i] = arguments[_i];
|
|
31
|
+
}
|
|
32
|
+
return "The number of constructor arguments in the derived class " +
|
|
33
|
+
(values[0] + " must be >= than the number of constructor arguments of its base class.");
|
|
34
|
+
};
|
|
24
35
|
exports.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = "Invalid Container constructor argument. Container options " +
|
|
25
36
|
"must be an object.";
|
|
26
37
|
exports.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = "Invalid Container option. Default scope must " +
|
|
27
38
|
"be a string ('singleton' or 'transient').";
|
|
28
39
|
exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = "Invalid Container option. Auto bind injectable must " +
|
|
29
40
|
"be a boolean";
|
|
41
|
+
exports.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = "Invalid Container option. Skip base check must " +
|
|
42
|
+
"be a boolean";
|
|
30
43
|
exports.MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
|
|
31
44
|
exports.POST_CONSTRUCT_ERROR = function () {
|
|
32
45
|
var values = [];
|