inversify 4.11.0 → 5.0.1
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/.auditignore +2 -0
- package/CHANGELOG.md +19 -0
- package/README.md +5 -5
- package/amd/annotation/decorator_utils.js +1 -1
- package/amd/bindings/binding.js +2 -2
- package/amd/constants/error_msgs.js +10 -2
- package/amd/container/container.js +35 -34
- package/amd/container/container_module.js +3 -3
- package/amd/inversify.js +3 -2
- package/amd/planning/context.js +2 -2
- package/amd/planning/planner.js +7 -0
- package/amd/planning/reflection_utils.js +2 -6
- package/amd/planning/request.js +2 -2
- package/amd/planning/target.js +2 -2
- package/amd/resolution/resolver.js +4 -4
- package/amd/utils/id.js +9 -0
- package/dts/bindings/binding.d.ts +1 -1
- package/dts/constants/error_msgs.d.ts +2 -2
- package/dts/container/container.d.ts +2 -2
- package/dts/container/container_module.d.ts +2 -2
- package/dts/interfaces/interfaces.d.ts +8 -7
- package/dts/inversify.d.ts +2 -2
- package/dts/planning/context.d.ts +1 -1
- package/dts/planning/reflection_utils.d.ts +3 -1
- package/dts/planning/request.d.ts +1 -1
- package/dts/planning/target.d.ts +1 -1
- package/dts/utils/id.d.ts +2 -0
- package/dts/utils/template.d.ts +1 -0
- package/es/annotation/decorator_utils.js +1 -1
- package/es/bindings/binding.js +2 -2
- package/es/constants/error_msgs.js +10 -2
- package/es/container/container.js +35 -34
- package/es/container/container_module.js +3 -3
- package/es/inversify.js +2 -2
- package/es/planning/context.js +2 -2
- package/es/planning/planner.js +8 -1
- package/es/planning/reflection_utils.js +1 -7
- package/es/planning/request.js +2 -2
- package/es/planning/target.js +2 -2
- package/es/resolution/resolver.js +4 -4
- package/es/utils/id.js +5 -0
- package/lib/annotation/decorator_utils.js +1 -1
- package/lib/bindings/binding.js +2 -2
- package/lib/constants/error_msgs.js +10 -2
- package/lib/container/container.js +35 -34
- package/lib/container/container_module.js +3 -3
- package/lib/inversify.js +3 -2
- package/lib/planning/context.js +2 -2
- package/lib/planning/planner.js +7 -0
- package/lib/planning/reflection_utils.js +2 -6
- package/lib/planning/request.js +2 -2
- package/lib/planning/target.js +2 -2
- package/lib/resolution/resolver.js +4 -4
- package/lib/utils/id.js +7 -0
- package/package.json +17 -17
- package/amd/utils/guid.js +0 -14
- package/es/utils/guid.js +0 -10
- package/lib/utils/guid.js +0 -12
|
@@ -22,14 +22,22 @@ export var INVALID_TO_SELF_VALUE = "The toSelf function can only be applied when
|
|
|
22
22
|
"used as service identifier";
|
|
23
23
|
export var INVALID_DECORATOR_OPERATION = "The @inject @multiInject @tagged and @named decorators " +
|
|
24
24
|
"must be applied to the parameters of a class constructor or a class property.";
|
|
25
|
-
export var
|
|
26
|
-
|
|
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
|
+
};
|
|
27
33
|
export var CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = "Invalid Container constructor argument. Container options " +
|
|
28
34
|
"must be an object.";
|
|
29
35
|
export var CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = "Invalid Container option. Default scope must " +
|
|
30
36
|
"be a string ('singleton' or 'transient').";
|
|
31
37
|
export var CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = "Invalid Container option. Auto bind injectable must " +
|
|
32
38
|
"be a boolean";
|
|
39
|
+
export var CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = "Invalid Container option. Skip base check must " +
|
|
40
|
+
"be a boolean";
|
|
33
41
|
export var MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
|
|
34
42
|
export var POST_CONSTRUCT_ERROR = function () {
|
|
35
43
|
var values = [];
|
|
@@ -41,40 +41,42 @@ import { MetadataReader } from "../planning/metadata_reader";
|
|
|
41
41
|
import { createMockRequest, getBindingDictionary, plan } from "../planning/planner";
|
|
42
42
|
import { resolve } from "../resolution/resolver";
|
|
43
43
|
import { BindingToSyntax } from "../syntax/binding_to_syntax";
|
|
44
|
-
import {
|
|
44
|
+
import { id } from "../utils/id";
|
|
45
45
|
import { getServiceIdentifierAsString } from "../utils/serialization";
|
|
46
46
|
import { ContainerSnapshot } from "./container_snapshot";
|
|
47
47
|
import { Lookup } from "./lookup";
|
|
48
48
|
var Container = (function () {
|
|
49
49
|
function Container(containerOptions) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
if (containerOptions.defaultScope !== undefined &&
|
|
56
|
-
containerOptions.defaultScope !== BindingScopeEnum.Singleton &&
|
|
57
|
-
containerOptions.defaultScope !== BindingScopeEnum.Transient &&
|
|
58
|
-
containerOptions.defaultScope !== BindingScopeEnum.Request) {
|
|
59
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
60
|
-
}
|
|
61
|
-
if (containerOptions.autoBindInjectable !== undefined &&
|
|
62
|
-
typeof containerOptions.autoBindInjectable !== "boolean") {
|
|
63
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
this.options = {
|
|
67
|
-
autoBindInjectable: containerOptions.autoBindInjectable,
|
|
68
|
-
defaultScope: containerOptions.defaultScope
|
|
69
|
-
};
|
|
50
|
+
var options = containerOptions || {};
|
|
51
|
+
if (typeof options !== "object") {
|
|
52
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
|
|
70
53
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
autoBindInjectable: false,
|
|
74
|
-
defaultScope: BindingScopeEnum.Transient
|
|
75
|
-
};
|
|
54
|
+
if (options.defaultScope === undefined) {
|
|
55
|
+
options.defaultScope = BindingScopeEnum.Transient;
|
|
76
56
|
}
|
|
77
|
-
|
|
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;
|
|
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
|
+
};
|
|
79
|
+
this.id = id();
|
|
78
80
|
this._bindingDictionary = new Lookup();
|
|
79
81
|
this._snapshots = [];
|
|
80
82
|
this._middleware = null;
|
|
@@ -105,7 +107,7 @@ var Container = (function () {
|
|
|
105
107
|
var getHelpers = this._getContainerModuleHelpersFactory();
|
|
106
108
|
for (var _a = 0, modules_1 = modules; _a < modules_1.length; _a++) {
|
|
107
109
|
var currentModule = modules_1[_a];
|
|
108
|
-
var containerModuleHelpers = getHelpers(currentModule.
|
|
110
|
+
var containerModuleHelpers = getHelpers(currentModule.id);
|
|
109
111
|
currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction);
|
|
110
112
|
}
|
|
111
113
|
};
|
|
@@ -125,7 +127,7 @@ var Container = (function () {
|
|
|
125
127
|
case 1:
|
|
126
128
|
if (!(_a < modules_2.length)) return [3, 4];
|
|
127
129
|
currentModule = modules_2[_a];
|
|
128
|
-
containerModuleHelpers = getHelpers(currentModule.
|
|
130
|
+
containerModuleHelpers = getHelpers(currentModule.id);
|
|
129
131
|
return [4, currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction)];
|
|
130
132
|
case 2:
|
|
131
133
|
_b.sent();
|
|
@@ -148,7 +150,7 @@ var Container = (function () {
|
|
|
148
150
|
return item.moduleId === expected;
|
|
149
151
|
}; };
|
|
150
152
|
modules.forEach(function (module) {
|
|
151
|
-
var condition = conditionFactory(module.
|
|
153
|
+
var condition = conditionFactory(module.id);
|
|
152
154
|
_this._bindingDictionary.removeByCondition(condition);
|
|
153
155
|
});
|
|
154
156
|
};
|
|
@@ -206,8 +208,8 @@ var Container = (function () {
|
|
|
206
208
|
this._bindingDictionary = snapshot.bindings;
|
|
207
209
|
this._middleware = snapshot.middleware;
|
|
208
210
|
};
|
|
209
|
-
Container.prototype.createChild = function () {
|
|
210
|
-
var child = new Container();
|
|
211
|
+
Container.prototype.createChild = function (containerOptions) {
|
|
212
|
+
var child = new Container(containerOptions || this.options);
|
|
211
213
|
child.parent = this;
|
|
212
214
|
return child;
|
|
213
215
|
};
|
|
@@ -241,9 +243,8 @@ var Container = (function () {
|
|
|
241
243
|
return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
242
244
|
};
|
|
243
245
|
Container.prototype.resolve = function (constructorFunction) {
|
|
244
|
-
var tempContainer =
|
|
246
|
+
var tempContainer = this.createChild();
|
|
245
247
|
tempContainer.bind(constructorFunction).toSelf();
|
|
246
|
-
tempContainer.parent = this;
|
|
247
248
|
return tempContainer.get(constructorFunction);
|
|
248
249
|
};
|
|
249
250
|
Container.prototype._getContainerModuleHelpersFactory = function () {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { id } from "../utils/id";
|
|
2
2
|
var ContainerModule = (function () {
|
|
3
3
|
function ContainerModule(registry) {
|
|
4
|
-
this.
|
|
4
|
+
this.id = id();
|
|
5
5
|
this.registry = registry;
|
|
6
6
|
}
|
|
7
7
|
return ContainerModule;
|
|
@@ -9,7 +9,7 @@ var ContainerModule = (function () {
|
|
|
9
9
|
export { ContainerModule };
|
|
10
10
|
var AsyncContainerModule = (function () {
|
|
11
11
|
function AsyncContainerModule(registry) {
|
|
12
|
-
this.
|
|
12
|
+
this.id = id();
|
|
13
13
|
this.registry = registry;
|
|
14
14
|
}
|
|
15
15
|
return AsyncContainerModule;
|
package/es/inversify.js
CHANGED
|
@@ -2,7 +2,7 @@ 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";
|
|
@@ -13,7 +13,7 @@ export { multiInject } from "./annotation/multi_inject";
|
|
|
13
13
|
export { targetName } from "./annotation/target_name";
|
|
14
14
|
export { postConstruct } from "./annotation/post_construct";
|
|
15
15
|
export { MetadataReader } from "./planning/metadata_reader";
|
|
16
|
-
export {
|
|
16
|
+
export { id } from "./utils/id";
|
|
17
17
|
export { decorate } from "./annotation/decorator_utils";
|
|
18
18
|
export { traverseAncerstors, taggedConstraint, namedConstraint, typeConstraint } from "./syntax/constraint_helpers";
|
|
19
19
|
export { getServiceIdentifierAsString } from "./utils/serialization";
|
package/es/planning/context.js
CHANGED
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
|
});
|
|
@@ -23,12 +23,6 @@ function getTargets(metadataReader, constructorName, func, isBaseClass) {
|
|
|
23
23
|
var constructorTargets = getConstructorArgsAsTargets(isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata, iterations);
|
|
24
24
|
var propertyTargets = getClassPropsAsTargets(metadataReader, func);
|
|
25
25
|
var targets = constructorTargets.concat(propertyTargets);
|
|
26
|
-
var baseClassDependencyCount = getBaseClassDependencyCount(metadataReader, func);
|
|
27
|
-
if (targets.length < baseClassDependencyCount) {
|
|
28
|
-
var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_1 +
|
|
29
|
-
constructorName + ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_2;
|
|
30
|
-
throw new Error(error);
|
|
31
|
-
}
|
|
32
26
|
return targets;
|
|
33
27
|
}
|
|
34
28
|
function getConstructorArgsAsTarget(index, isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata) {
|
|
@@ -123,4 +117,4 @@ function formatTargetMetadata(targetMetadata) {
|
|
|
123
117
|
unmanaged: targetMetadataMap[METADATA_KEY.UNMANAGED_TAG]
|
|
124
118
|
};
|
|
125
119
|
}
|
|
126
|
-
export { getDependencies };
|
|
120
|
+
export { getDependencies, getBaseClassDependencyCount, getFunctionName };
|
package/es/planning/request.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { id } from "../utils/id";
|
|
2
2
|
var Request = (function () {
|
|
3
3
|
function Request(serviceIdentifier, parentContext, parentRequest, bindings, target) {
|
|
4
|
-
this.
|
|
4
|
+
this.id = id();
|
|
5
5
|
this.serviceIdentifier = serviceIdentifier;
|
|
6
6
|
this.parentContext = parentContext;
|
|
7
7
|
this.parentRequest = parentRequest;
|
package/es/planning/target.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as METADATA_KEY from "../constants/metadata_keys";
|
|
2
|
-
import {
|
|
2
|
+
import { id } from "../utils/id";
|
|
3
3
|
import { Metadata } from "./metadata";
|
|
4
4
|
import { QueryableString } from "./queryable_string";
|
|
5
5
|
var Target = (function () {
|
|
6
6
|
function Target(type, name, serviceIdentifier, namedOrTagged) {
|
|
7
|
-
this.
|
|
7
|
+
this.id = id();
|
|
8
8
|
this.type = type;
|
|
9
9
|
this.serviceIdentifier = serviceIdentifier;
|
|
10
10
|
this.name = new QueryableString(name || "");
|
|
@@ -45,8 +45,8 @@ var _resolveRequest = function (requestScope) {
|
|
|
45
45
|
}
|
|
46
46
|
if (isRequestSingleton &&
|
|
47
47
|
requestScope !== null &&
|
|
48
|
-
requestScope.has(binding_1.
|
|
49
|
-
return requestScope.get(binding_1.
|
|
48
|
+
requestScope.has(binding_1.id)) {
|
|
49
|
+
return requestScope.get(binding_1.id);
|
|
50
50
|
}
|
|
51
51
|
if (binding_1.type === BindingTypeEnum.ConstantValue) {
|
|
52
52
|
result = binding_1.cache;
|
|
@@ -82,8 +82,8 @@ var _resolveRequest = function (requestScope) {
|
|
|
82
82
|
}
|
|
83
83
|
if (isRequestSingleton &&
|
|
84
84
|
requestScope !== null &&
|
|
85
|
-
!requestScope.has(binding_1.
|
|
86
|
-
requestScope.set(binding_1.
|
|
85
|
+
!requestScope.has(binding_1.id)) {
|
|
86
|
+
requestScope.set(binding_1.id, result);
|
|
87
87
|
}
|
|
88
88
|
return result;
|
|
89
89
|
}
|
package/es/utils/id.js
ADDED
|
@@ -30,7 +30,7 @@ function _tagParameterOrProperty(metadataKey, annotationTarget, propertyName, me
|
|
|
30
30
|
for (var _i = 0, paramOrPropertyMetadata_1 = paramOrPropertyMetadata; _i < paramOrPropertyMetadata_1.length; _i++) {
|
|
31
31
|
var m = paramOrPropertyMetadata_1[_i];
|
|
32
32
|
if (m.key === metadata.key) {
|
|
33
|
-
throw new Error(ERROR_MSGS.DUPLICATED_METADATA + " " + m.key);
|
|
33
|
+
throw new Error(ERROR_MSGS.DUPLICATED_METADATA + " " + m.key.toString());
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
package/lib/bindings/binding.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var literal_types_1 = require("../constants/literal_types");
|
|
4
|
-
var
|
|
4
|
+
var id_1 = require("../utils/id");
|
|
5
5
|
var Binding = (function () {
|
|
6
6
|
function Binding(serviceIdentifier, scope) {
|
|
7
|
-
this.
|
|
7
|
+
this.id = id_1.id();
|
|
8
8
|
this.activated = false;
|
|
9
9
|
this.serviceIdentifier = serviceIdentifier;
|
|
10
10
|
this.scope = scope;
|
|
@@ -24,14 +24,22 @@ exports.INVALID_TO_SELF_VALUE = "The toSelf function can only be applied when a
|
|
|
24
24
|
"used as service identifier";
|
|
25
25
|
exports.INVALID_DECORATOR_OPERATION = "The @inject @multiInject @tagged and @named decorators " +
|
|
26
26
|
"must be applied to the parameters of a class constructor or a class property.";
|
|
27
|
-
exports.
|
|
28
|
-
|
|
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
|
+
};
|
|
29
35
|
exports.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = "Invalid Container constructor argument. Container options " +
|
|
30
36
|
"must be an object.";
|
|
31
37
|
exports.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = "Invalid Container option. Default scope must " +
|
|
32
38
|
"be a string ('singleton' or 'transient').";
|
|
33
39
|
exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = "Invalid Container option. Auto bind injectable must " +
|
|
34
40
|
"be a boolean";
|
|
41
|
+
exports.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = "Invalid Container option. Skip base check must " +
|
|
42
|
+
"be a boolean";
|
|
35
43
|
exports.MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
|
|
36
44
|
exports.POST_CONSTRUCT_ERROR = function () {
|
|
37
45
|
var values = [];
|
|
@@ -43,40 +43,42 @@ var metadata_reader_1 = require("../planning/metadata_reader");
|
|
|
43
43
|
var planner_1 = require("../planning/planner");
|
|
44
44
|
var resolver_1 = require("../resolution/resolver");
|
|
45
45
|
var binding_to_syntax_1 = require("../syntax/binding_to_syntax");
|
|
46
|
-
var
|
|
46
|
+
var id_1 = require("../utils/id");
|
|
47
47
|
var serialization_1 = require("../utils/serialization");
|
|
48
48
|
var container_snapshot_1 = require("./container_snapshot");
|
|
49
49
|
var lookup_1 = require("./lookup");
|
|
50
50
|
var Container = (function () {
|
|
51
51
|
function Container(containerOptions) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
if (containerOptions.defaultScope !== undefined &&
|
|
58
|
-
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
|
|
59
|
-
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
|
|
60
|
-
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
|
|
61
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
62
|
-
}
|
|
63
|
-
if (containerOptions.autoBindInjectable !== undefined &&
|
|
64
|
-
typeof containerOptions.autoBindInjectable !== "boolean") {
|
|
65
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
this.options = {
|
|
69
|
-
autoBindInjectable: containerOptions.autoBindInjectable,
|
|
70
|
-
defaultScope: containerOptions.defaultScope
|
|
71
|
-
};
|
|
52
|
+
var options = containerOptions || {};
|
|
53
|
+
if (typeof options !== "object") {
|
|
54
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
|
|
72
55
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
autoBindInjectable: false,
|
|
76
|
-
defaultScope: literal_types_1.BindingScopeEnum.Transient
|
|
77
|
-
};
|
|
56
|
+
if (options.defaultScope === undefined) {
|
|
57
|
+
options.defaultScope = literal_types_1.BindingScopeEnum.Transient;
|
|
78
58
|
}
|
|
79
|
-
|
|
59
|
+
else if (options.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
|
|
60
|
+
options.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
|
|
61
|
+
options.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
|
|
62
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
63
|
+
}
|
|
64
|
+
if (options.autoBindInjectable === undefined) {
|
|
65
|
+
options.autoBindInjectable = false;
|
|
66
|
+
}
|
|
67
|
+
else if (typeof options.autoBindInjectable !== "boolean") {
|
|
68
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
69
|
+
}
|
|
70
|
+
if (options.skipBaseClassChecks === undefined) {
|
|
71
|
+
options.skipBaseClassChecks = false;
|
|
72
|
+
}
|
|
73
|
+
else if (typeof options.skipBaseClassChecks !== "boolean") {
|
|
74
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK);
|
|
75
|
+
}
|
|
76
|
+
this.options = {
|
|
77
|
+
autoBindInjectable: options.autoBindInjectable,
|
|
78
|
+
defaultScope: options.defaultScope,
|
|
79
|
+
skipBaseClassChecks: options.skipBaseClassChecks
|
|
80
|
+
};
|
|
81
|
+
this.id = id_1.id();
|
|
80
82
|
this._bindingDictionary = new lookup_1.Lookup();
|
|
81
83
|
this._snapshots = [];
|
|
82
84
|
this._middleware = null;
|
|
@@ -107,7 +109,7 @@ var Container = (function () {
|
|
|
107
109
|
var getHelpers = this._getContainerModuleHelpersFactory();
|
|
108
110
|
for (var _a = 0, modules_1 = modules; _a < modules_1.length; _a++) {
|
|
109
111
|
var currentModule = modules_1[_a];
|
|
110
|
-
var containerModuleHelpers = getHelpers(currentModule.
|
|
112
|
+
var containerModuleHelpers = getHelpers(currentModule.id);
|
|
111
113
|
currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction);
|
|
112
114
|
}
|
|
113
115
|
};
|
|
@@ -127,7 +129,7 @@ var Container = (function () {
|
|
|
127
129
|
case 1:
|
|
128
130
|
if (!(_a < modules_2.length)) return [3, 4];
|
|
129
131
|
currentModule = modules_2[_a];
|
|
130
|
-
containerModuleHelpers = getHelpers(currentModule.
|
|
132
|
+
containerModuleHelpers = getHelpers(currentModule.id);
|
|
131
133
|
return [4, currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction)];
|
|
132
134
|
case 2:
|
|
133
135
|
_b.sent();
|
|
@@ -150,7 +152,7 @@ var Container = (function () {
|
|
|
150
152
|
return item.moduleId === expected;
|
|
151
153
|
}; };
|
|
152
154
|
modules.forEach(function (module) {
|
|
153
|
-
var condition = conditionFactory(module.
|
|
155
|
+
var condition = conditionFactory(module.id);
|
|
154
156
|
_this._bindingDictionary.removeByCondition(condition);
|
|
155
157
|
});
|
|
156
158
|
};
|
|
@@ -208,8 +210,8 @@ var Container = (function () {
|
|
|
208
210
|
this._bindingDictionary = snapshot.bindings;
|
|
209
211
|
this._middleware = snapshot.middleware;
|
|
210
212
|
};
|
|
211
|
-
Container.prototype.createChild = function () {
|
|
212
|
-
var child = new Container();
|
|
213
|
+
Container.prototype.createChild = function (containerOptions) {
|
|
214
|
+
var child = new Container(containerOptions || this.options);
|
|
213
215
|
child.parent = this;
|
|
214
216
|
return child;
|
|
215
217
|
};
|
|
@@ -243,9 +245,8 @@ var Container = (function () {
|
|
|
243
245
|
return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
244
246
|
};
|
|
245
247
|
Container.prototype.resolve = function (constructorFunction) {
|
|
246
|
-
var tempContainer =
|
|
248
|
+
var tempContainer = this.createChild();
|
|
247
249
|
tempContainer.bind(constructorFunction).toSelf();
|
|
248
|
-
tempContainer.parent = this;
|
|
249
250
|
return tempContainer.get(constructorFunction);
|
|
250
251
|
};
|
|
251
252
|
Container.prototype._getContainerModuleHelpersFactory = function () {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var
|
|
3
|
+
var id_1 = require("../utils/id");
|
|
4
4
|
var ContainerModule = (function () {
|
|
5
5
|
function ContainerModule(registry) {
|
|
6
|
-
this.
|
|
6
|
+
this.id = id_1.id();
|
|
7
7
|
this.registry = registry;
|
|
8
8
|
}
|
|
9
9
|
return ContainerModule;
|
|
@@ -11,7 +11,7 @@ var ContainerModule = (function () {
|
|
|
11
11
|
exports.ContainerModule = ContainerModule;
|
|
12
12
|
var AsyncContainerModule = (function () {
|
|
13
13
|
function AsyncContainerModule(registry) {
|
|
14
|
-
this.
|
|
14
|
+
this.id = id_1.id();
|
|
15
15
|
this.registry = registry;
|
|
16
16
|
}
|
|
17
17
|
return AsyncContainerModule;
|
package/lib/inversify.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.BindingScopeEnum = literal_types_1.BindingScopeEnum;
|
|
|
9
9
|
exports.BindingTypeEnum = literal_types_1.BindingTypeEnum;
|
|
10
10
|
exports.TargetTypeEnum = literal_types_1.TargetTypeEnum;
|
|
11
11
|
var container_module_1 = require("./container/container_module");
|
|
12
|
+
exports.AsyncContainerModule = container_module_1.AsyncContainerModule;
|
|
12
13
|
exports.ContainerModule = container_module_1.ContainerModule;
|
|
13
14
|
var injectable_1 = require("./annotation/injectable");
|
|
14
15
|
exports.injectable = injectable_1.injectable;
|
|
@@ -31,8 +32,8 @@ var post_construct_1 = require("./annotation/post_construct");
|
|
|
31
32
|
exports.postConstruct = post_construct_1.postConstruct;
|
|
32
33
|
var metadata_reader_1 = require("./planning/metadata_reader");
|
|
33
34
|
exports.MetadataReader = metadata_reader_1.MetadataReader;
|
|
34
|
-
var
|
|
35
|
-
exports.
|
|
35
|
+
var id_1 = require("./utils/id");
|
|
36
|
+
exports.id = id_1.id;
|
|
36
37
|
var decorator_utils_1 = require("./annotation/decorator_utils");
|
|
37
38
|
exports.decorate = decorator_utils_1.decorate;
|
|
38
39
|
var constraint_helpers_1 = require("./syntax/constraint_helpers");
|
package/lib/planning/context.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var
|
|
3
|
+
var id_1 = require("../utils/id");
|
|
4
4
|
var Context = (function () {
|
|
5
5
|
function Context(container) {
|
|
6
|
-
this.
|
|
6
|
+
this.id = id_1.id();
|
|
7
7
|
this.container = container;
|
|
8
8
|
}
|
|
9
9
|
Context.prototype.addPlan = function (plan) {
|
package/lib/planning/planner.js
CHANGED
|
@@ -104,6 +104,13 @@ function _createSubRequests(metadataReader, avoidConstraints, serviceIdentifier,
|
|
|
104
104
|
}
|
|
105
105
|
if (binding.type === literal_types_1.BindingTypeEnum.Instance && binding.implementationType !== null) {
|
|
106
106
|
var dependencies = reflection_utils_1.getDependencies(metadataReader, binding.implementationType);
|
|
107
|
+
if (!context.container.options.skipBaseClassChecks) {
|
|
108
|
+
var baseClassDependencyCount = reflection_utils_1.getBaseClassDependencyCount(metadataReader, binding.implementationType);
|
|
109
|
+
if (dependencies.length < baseClassDependencyCount) {
|
|
110
|
+
var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH(reflection_utils_1.getFunctionName(binding.implementationType));
|
|
111
|
+
throw new Error(error);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
107
114
|
dependencies.forEach(function (dependency) {
|
|
108
115
|
_createSubRequests(metadataReader, false, dependency.serviceIdentifier, context, subChildRequest, dependency);
|
|
109
116
|
});
|
|
@@ -5,6 +5,7 @@ var ERROR_MSGS = require("../constants/error_msgs");
|
|
|
5
5
|
var literal_types_1 = require("../constants/literal_types");
|
|
6
6
|
var METADATA_KEY = require("../constants/metadata_keys");
|
|
7
7
|
var serialization_1 = require("../utils/serialization");
|
|
8
|
+
exports.getFunctionName = serialization_1.getFunctionName;
|
|
8
9
|
var target_1 = require("./target");
|
|
9
10
|
function getDependencies(metadataReader, func) {
|
|
10
11
|
var constructorName = serialization_1.getFunctionName(func);
|
|
@@ -26,12 +27,6 @@ function getTargets(metadataReader, constructorName, func, isBaseClass) {
|
|
|
26
27
|
var constructorTargets = getConstructorArgsAsTargets(isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata, iterations);
|
|
27
28
|
var propertyTargets = getClassPropsAsTargets(metadataReader, func);
|
|
28
29
|
var targets = constructorTargets.concat(propertyTargets);
|
|
29
|
-
var baseClassDependencyCount = getBaseClassDependencyCount(metadataReader, func);
|
|
30
|
-
if (targets.length < baseClassDependencyCount) {
|
|
31
|
-
var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_1 +
|
|
32
|
-
constructorName + ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_2;
|
|
33
|
-
throw new Error(error);
|
|
34
|
-
}
|
|
35
30
|
return targets;
|
|
36
31
|
}
|
|
37
32
|
function getConstructorArgsAsTarget(index, isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata) {
|
|
@@ -114,6 +109,7 @@ function getBaseClassDependencyCount(metadataReader, func) {
|
|
|
114
109
|
return 0;
|
|
115
110
|
}
|
|
116
111
|
}
|
|
112
|
+
exports.getBaseClassDependencyCount = getBaseClassDependencyCount;
|
|
117
113
|
function formatTargetMetadata(targetMetadata) {
|
|
118
114
|
var targetMetadataMap = {};
|
|
119
115
|
targetMetadata.forEach(function (m) {
|
package/lib/planning/request.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var
|
|
3
|
+
var id_1 = require("../utils/id");
|
|
4
4
|
var Request = (function () {
|
|
5
5
|
function Request(serviceIdentifier, parentContext, parentRequest, bindings, target) {
|
|
6
|
-
this.
|
|
6
|
+
this.id = id_1.id();
|
|
7
7
|
this.serviceIdentifier = serviceIdentifier;
|
|
8
8
|
this.parentContext = parentContext;
|
|
9
9
|
this.parentRequest = parentRequest;
|
package/lib/planning/target.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var METADATA_KEY = require("../constants/metadata_keys");
|
|
4
|
-
var
|
|
4
|
+
var id_1 = require("../utils/id");
|
|
5
5
|
var metadata_1 = require("./metadata");
|
|
6
6
|
var queryable_string_1 = require("./queryable_string");
|
|
7
7
|
var Target = (function () {
|
|
8
8
|
function Target(type, name, serviceIdentifier, namedOrTagged) {
|
|
9
|
-
this.
|
|
9
|
+
this.id = id_1.id();
|
|
10
10
|
this.type = type;
|
|
11
11
|
this.serviceIdentifier = serviceIdentifier;
|
|
12
12
|
this.name = new queryable_string_1.QueryableString(name || "");
|
|
@@ -47,8 +47,8 @@ var _resolveRequest = function (requestScope) {
|
|
|
47
47
|
}
|
|
48
48
|
if (isRequestSingleton &&
|
|
49
49
|
requestScope !== null &&
|
|
50
|
-
requestScope.has(binding_1.
|
|
51
|
-
return requestScope.get(binding_1.
|
|
50
|
+
requestScope.has(binding_1.id)) {
|
|
51
|
+
return requestScope.get(binding_1.id);
|
|
52
52
|
}
|
|
53
53
|
if (binding_1.type === literal_types_1.BindingTypeEnum.ConstantValue) {
|
|
54
54
|
result = binding_1.cache;
|
|
@@ -84,8 +84,8 @@ var _resolveRequest = function (requestScope) {
|
|
|
84
84
|
}
|
|
85
85
|
if (isRequestSingleton &&
|
|
86
86
|
requestScope !== null &&
|
|
87
|
-
!requestScope.has(binding_1.
|
|
88
|
-
requestScope.set(binding_1.
|
|
87
|
+
!requestScope.has(binding_1.id)) {
|
|
88
|
+
requestScope.set(binding_1.id, result);
|
|
89
89
|
}
|
|
90
90
|
return result;
|
|
91
91
|
}
|