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
package/.auditignore
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
All notable changes to this project from 4.14.0 forward will be documented in this file.
|
|
3
|
+
|
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [4.14.0] - 2018-10-16
|
|
10
|
+
### Added
|
|
11
|
+
- Updating constructor injection wiki document with concrete injection example #922
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- Change GUID to incremented counter for better performance #882
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
- fix broken compilation by adding `.toString()` so symbols serialization #893
|
|
18
|
+
- Fix problem with applying options on Container.resolve (fix #914) #915
|
|
19
|
+
- Fixed documentation issues
|
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
|
|
20
20
|
|
|
21
21
|
## About
|
|
22
|
-
InversifyJS is a lightweight
|
|
22
|
+
InversifyJS is a lightweight inversion of control (IoC) container for TypeScript and JavaScript apps.
|
|
23
23
|
An IoC container uses a class constructor to identify and inject its dependencies.
|
|
24
24
|
InversifyJS has a friendly API and encourages the usage of the best OOP and IoC practices.
|
|
25
25
|
|
|
@@ -54,7 +54,7 @@ InversifyJS has been developed with 4 main goals:
|
|
|
54
54
|
|
|
55
55
|
## Some companies using InversifyJS
|
|
56
56
|
|
|
57
|
-
[<img src="https://avatars0.githubusercontent.com/u/6154722?s=200&v=4" width="100" />](https://opensource.microsoft.com/) [<img src="https://pbs.twimg.com/profile_images/827249559046909954/SyaBPcH8_400x400.jpg" width="100" />](http://acia.aon.com/index.php/home/) [<img src="https://avatars3.githubusercontent.com/u/114767?s=200&v=4" width="100" />](https://www.lonelyplanet.com/) [<img src="https://avatars0.githubusercontent.com/u/25283328?s=200&v=4" width="100" />](https://jincor.com/) [<img src="https://avatars1.githubusercontent.com/u/1957282?s=200&v=4" width="100" />](https://www.web-computing.de/) [<img src="https://avatars1.githubusercontent.com/u/17648048?s=200&v=4" width="100" />](https://dcos.io/) [<img src="https://avatars0.githubusercontent.com/u/16970371?s=200&v=4" width="100" />](https://typefox.io/) [<img src="https://avatars0.githubusercontent.com/u/18010308?s=200&v=4" width="100" />](https://code4.ro/) [<img src="https://user-images.githubusercontent.com/10656223/33888109-fae0852e-df43-11e7-97f6-9db543da0bde.png" width="100">](http://www.baidu.com/) [<img src="https://avatars2.githubusercontent.com/u/8085382?s=200&v=4" width="100" />](https://www.imdada.cn/) [<img src="https://avatars2.githubusercontent.com/u/17041151?s=200&v=4" width="100" />](https://www.ato.gov.au/) [<img src="https://avatars1.githubusercontent.com/u/14963540?s=200&v=4" width="100" />](https://www.kaneoh.com/) [<img src="https://avatars0.githubusercontent.com/u/26021686?s=200&v=4" width="100" />](https://particl.io/) [<img src="https://avatars2.githubusercontent.com/u/24523195?s=200&v=4" width="100" />](https://slackmap.com/) [<img src="https://avatars3.githubusercontent.com/u/16556899?s=200&v=4" width="100" />](https://www.go1.com/) [<img src="https://avatars3.githubusercontent.com/u/23475730?s=200&v=4" width="100" />](http://www.stellwagengroup.com/stellwagen-technology/) [<img src="https://avatars1.githubusercontent.com/u/15262567?s=200&v=4" width="100" />](https://www.edrlab.org/) [<img src="https://avatars1.githubusercontent.com/u/10072104?s=200&v=4" width="100" />](https://www.goodgamestudios.com/) [<img src="https://avatars2.githubusercontent.com/u/13613760?s=200&v=4" width="100" />](https://freshfox.at/) [<img src="https://avatars1.githubusercontent.com/u/864482?s=200&v=4" width="100" />](https://schubergphilis.com/)
|
|
57
|
+
[<img src="https://avatars0.githubusercontent.com/u/6154722?s=200&v=4" width="100" />](https://opensource.microsoft.com/)[<img src="https://avatars2.githubusercontent.com/u/69631?s=200&v=4" width="100" />](https://code.facebook.com/projects/1021334114569758/nuclide/)[<img src="https://avatars0.githubusercontent.com/u/2232217?s=200&v=4" width="100" />](https://aws.github.io/aws-amplify/)[<img src="https://avatars0.githubusercontent.com/u/1520648?s=200&v=4" width="100" />](https://www.plainconcepts.com/)[<img src="https://avatars3.githubusercontent.com/u/6962987?s=200&v=4" width="100" />](https://api.slack.com/)[<img src="https://pbs.twimg.com/profile_images/827249559046909954/SyaBPcH8_400x400.jpg" width="100" />](http://acia.aon.com/index.php/home/) [<img src="https://avatars3.githubusercontent.com/u/114767?s=200&v=4" width="100" />](https://www.lonelyplanet.com/) [<img src="https://avatars0.githubusercontent.com/u/25283328?s=200&v=4" width="100" />](https://jincor.com/) [<img src="https://avatars1.githubusercontent.com/u/1957282?s=200&v=4" width="100" />](https://www.web-computing.de/) [<img src="https://avatars1.githubusercontent.com/u/17648048?s=200&v=4" width="100" />](https://dcos.io/) [<img src="https://avatars0.githubusercontent.com/u/16970371?s=200&v=4" width="100" />](https://typefox.io/) [<img src="https://avatars0.githubusercontent.com/u/18010308?s=200&v=4" width="100" />](https://code4.ro/) [<img src="https://user-images.githubusercontent.com/10656223/33888109-fae0852e-df43-11e7-97f6-9db543da0bde.png" width="100">](http://www.baidu.com/) [<img src="https://avatars2.githubusercontent.com/u/8085382?s=200&v=4" width="100" />](https://www.imdada.cn/) [<img src="https://avatars2.githubusercontent.com/u/17041151?s=200&v=4" width="100" />](https://www.ato.gov.au/) [<img src="https://avatars1.githubusercontent.com/u/14963540?s=200&v=4" width="100" />](https://www.kaneoh.com/) [<img src="https://avatars0.githubusercontent.com/u/26021686?s=200&v=4" width="100" />](https://particl.io/) [<img src="https://avatars2.githubusercontent.com/u/24523195?s=200&v=4" width="100" />](https://slackmap.com/) [<img src="https://avatars3.githubusercontent.com/u/16556899?s=200&v=4" width="100" />](https://www.go1.com/) [<img src="https://avatars3.githubusercontent.com/u/23475730?s=200&v=4" width="100" />](http://www.stellwagengroup.com/stellwagen-technology/) [<img src="https://avatars1.githubusercontent.com/u/15262567?s=200&v=4" width="100" />](https://www.edrlab.org/) [<img src="https://avatars1.githubusercontent.com/u/10072104?s=200&v=4" width="100" />](https://www.goodgamestudios.com/) [<img src="https://avatars2.githubusercontent.com/u/13613760?s=200&v=4" width="100" />](https://freshfox.at/) [<img src="https://avatars1.githubusercontent.com/u/864482?s=200&v=4" width="100" />](https://schubergphilis.com/)
|
|
58
58
|
|
|
59
59
|
## Installation
|
|
60
60
|
|
|
@@ -109,16 +109,16 @@ Let's start by declaring some interfaces (abstractions).
|
|
|
109
109
|
```ts
|
|
110
110
|
// file interfaces.ts
|
|
111
111
|
|
|
112
|
-
interface Warrior {
|
|
112
|
+
export interface Warrior {
|
|
113
113
|
fight(): string;
|
|
114
114
|
sneak(): string;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
interface Weapon {
|
|
117
|
+
export interface Weapon {
|
|
118
118
|
hit(): string;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
interface ThrowableWeapon {
|
|
121
|
+
export interface ThrowableWeapon {
|
|
122
122
|
throw(): string;
|
|
123
123
|
}
|
|
124
124
|
```
|
|
@@ -29,7 +29,7 @@ define(["require", "exports", "../constants/error_msgs", "../constants/metadata_
|
|
|
29
29
|
for (var _i = 0, paramOrPropertyMetadata_1 = paramOrPropertyMetadata; _i < paramOrPropertyMetadata_1.length; _i++) {
|
|
30
30
|
var m = paramOrPropertyMetadata_1[_i];
|
|
31
31
|
if (m.key === metadata.key) {
|
|
32
|
-
throw new Error(ERROR_MSGS.DUPLICATED_METADATA + " " + m.key);
|
|
32
|
+
throw new Error(ERROR_MSGS.DUPLICATED_METADATA + " " + m.key.toString());
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
package/amd/bindings/binding.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
define(["require", "exports", "../constants/literal_types", "../utils/
|
|
1
|
+
define(["require", "exports", "../constants/literal_types", "../utils/id"], function (require, exports, literal_types_1, id_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
var Binding = (function () {
|
|
5
5
|
function Binding(serviceIdentifier, scope) {
|
|
6
|
-
this.
|
|
6
|
+
this.id = id_1.id();
|
|
7
7
|
this.activated = false;
|
|
8
8
|
this.serviceIdentifier = serviceIdentifier;
|
|
9
9
|
this.scope = scope;
|
|
@@ -25,14 +25,22 @@ define(["require", "exports"], function (require, exports) {
|
|
|
25
25
|
"used as service identifier";
|
|
26
26
|
exports.INVALID_DECORATOR_OPERATION = "The @inject @multiInject @tagged and @named decorators " +
|
|
27
27
|
"must be applied to the parameters of a class constructor or a class property.";
|
|
28
|
-
exports.
|
|
29
|
-
|
|
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
|
+
};
|
|
30
36
|
exports.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = "Invalid Container constructor argument. Container options " +
|
|
31
37
|
"must be an object.";
|
|
32
38
|
exports.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = "Invalid Container option. Default scope must " +
|
|
33
39
|
"be a string ('singleton' or 'transient').";
|
|
34
40
|
exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = "Invalid Container option. Auto bind injectable must " +
|
|
35
41
|
"be a boolean";
|
|
42
|
+
exports.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = "Invalid Container option. Skip base check must " +
|
|
43
|
+
"be a boolean";
|
|
36
44
|
exports.MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
|
|
37
45
|
exports.POST_CONSTRUCT_ERROR = function () {
|
|
38
46
|
var values = [];
|
|
@@ -33,39 +33,41 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
33
33
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
34
34
|
}
|
|
35
35
|
};
|
|
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/
|
|
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/id", "../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, id_1, serialization_1, container_snapshot_1, lookup_1) {
|
|
37
37
|
"use strict";
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
var Container = (function () {
|
|
40
40
|
function Container(containerOptions) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
if (containerOptions.defaultScope !== undefined &&
|
|
47
|
-
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
|
|
48
|
-
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
|
|
49
|
-
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
|
|
50
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
51
|
-
}
|
|
52
|
-
if (containerOptions.autoBindInjectable !== undefined &&
|
|
53
|
-
typeof containerOptions.autoBindInjectable !== "boolean") {
|
|
54
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
this.options = {
|
|
58
|
-
autoBindInjectable: containerOptions.autoBindInjectable,
|
|
59
|
-
defaultScope: containerOptions.defaultScope
|
|
60
|
-
};
|
|
41
|
+
var options = containerOptions || {};
|
|
42
|
+
if (typeof options !== "object") {
|
|
43
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
|
|
61
44
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
autoBindInjectable: false,
|
|
65
|
-
defaultScope: literal_types_1.BindingScopeEnum.Transient
|
|
66
|
-
};
|
|
45
|
+
if (options.defaultScope === undefined) {
|
|
46
|
+
options.defaultScope = literal_types_1.BindingScopeEnum.Transient;
|
|
67
47
|
}
|
|
68
|
-
|
|
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;
|
|
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
|
+
};
|
|
70
|
+
this.id = id_1.id();
|
|
69
71
|
this._bindingDictionary = new lookup_1.Lookup();
|
|
70
72
|
this._snapshots = [];
|
|
71
73
|
this._middleware = null;
|
|
@@ -96,7 +98,7 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
|
|
|
96
98
|
var getHelpers = this._getContainerModuleHelpersFactory();
|
|
97
99
|
for (var _a = 0, modules_1 = modules; _a < modules_1.length; _a++) {
|
|
98
100
|
var currentModule = modules_1[_a];
|
|
99
|
-
var containerModuleHelpers = getHelpers(currentModule.
|
|
101
|
+
var containerModuleHelpers = getHelpers(currentModule.id);
|
|
100
102
|
currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction);
|
|
101
103
|
}
|
|
102
104
|
};
|
|
@@ -116,7 +118,7 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
|
|
|
116
118
|
case 1:
|
|
117
119
|
if (!(_a < modules_2.length)) return [3, 4];
|
|
118
120
|
currentModule = modules_2[_a];
|
|
119
|
-
containerModuleHelpers = getHelpers(currentModule.
|
|
121
|
+
containerModuleHelpers = getHelpers(currentModule.id);
|
|
120
122
|
return [4, currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction)];
|
|
121
123
|
case 2:
|
|
122
124
|
_b.sent();
|
|
@@ -139,7 +141,7 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
|
|
|
139
141
|
return item.moduleId === expected;
|
|
140
142
|
}; };
|
|
141
143
|
modules.forEach(function (module) {
|
|
142
|
-
var condition = conditionFactory(module.
|
|
144
|
+
var condition = conditionFactory(module.id);
|
|
143
145
|
_this._bindingDictionary.removeByCondition(condition);
|
|
144
146
|
});
|
|
145
147
|
};
|
|
@@ -197,8 +199,8 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
|
|
|
197
199
|
this._bindingDictionary = snapshot.bindings;
|
|
198
200
|
this._middleware = snapshot.middleware;
|
|
199
201
|
};
|
|
200
|
-
Container.prototype.createChild = function () {
|
|
201
|
-
var child = new Container();
|
|
202
|
+
Container.prototype.createChild = function (containerOptions) {
|
|
203
|
+
var child = new Container(containerOptions || this.options);
|
|
202
204
|
child.parent = this;
|
|
203
205
|
return child;
|
|
204
206
|
};
|
|
@@ -232,9 +234,8 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
|
|
|
232
234
|
return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
233
235
|
};
|
|
234
236
|
Container.prototype.resolve = function (constructorFunction) {
|
|
235
|
-
var tempContainer =
|
|
237
|
+
var tempContainer = this.createChild();
|
|
236
238
|
tempContainer.bind(constructorFunction).toSelf();
|
|
237
|
-
tempContainer.parent = this;
|
|
238
239
|
return tempContainer.get(constructorFunction);
|
|
239
240
|
};
|
|
240
241
|
Container.prototype._getContainerModuleHelpersFactory = function () {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
define(["require", "exports", "../utils/
|
|
1
|
+
define(["require", "exports", "../utils/id"], function (require, exports, id_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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 @@ define(["require", "exports", "../utils/guid"], function (require, exports, guid
|
|
|
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/amd/inversify.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
define(["require", "exports", "./constants/metadata_keys", "./container/container", "./constants/literal_types", "./container/container_module", "./annotation/injectable", "./annotation/tagged", "./annotation/named", "./annotation/inject", "./annotation/optional", "./annotation/unmanaged", "./annotation/multi_inject", "./annotation/target_name", "./annotation/post_construct", "./planning/metadata_reader", "./utils/
|
|
1
|
+
define(["require", "exports", "./constants/metadata_keys", "./container/container", "./constants/literal_types", "./container/container_module", "./annotation/injectable", "./annotation/tagged", "./annotation/named", "./annotation/inject", "./annotation/optional", "./annotation/unmanaged", "./annotation/multi_inject", "./annotation/target_name", "./annotation/post_construct", "./planning/metadata_reader", "./utils/id", "./annotation/decorator_utils", "./syntax/constraint_helpers", "./utils/serialization", "./utils/binding_utils"], function (require, exports, keys, container_1, literal_types_1, container_module_1, injectable_1, tagged_1, named_1, inject_1, optional_1, unmanaged_1, multi_inject_1, target_name_1, post_construct_1, metadata_reader_1, id_1, decorator_utils_1, constraint_helpers_1, serialization_1, binding_utils_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.METADATA_KEY = keys;
|
|
@@ -6,6 +6,7 @@ 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;
|
|
@@ -18,7 +19,7 @@ define(["require", "exports", "./constants/metadata_keys", "./container/containe
|
|
|
18
19
|
exports.targetName = target_name_1.targetName;
|
|
19
20
|
exports.postConstruct = post_construct_1.postConstruct;
|
|
20
21
|
exports.MetadataReader = metadata_reader_1.MetadataReader;
|
|
21
|
-
exports.
|
|
22
|
+
exports.id = id_1.id;
|
|
22
23
|
exports.decorate = decorator_utils_1.decorate;
|
|
23
24
|
exports.traverseAncerstors = constraint_helpers_1.traverseAncerstors;
|
|
24
25
|
exports.taggedConstraint = constraint_helpers_1.taggedConstraint;
|
package/amd/planning/context.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
define(["require", "exports", "../utils/
|
|
1
|
+
define(["require", "exports", "../utils/id"], function (require, exports, id_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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/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
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", "../annotation/inject", "../constants/error_msgs",
|
|
|
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) {
|
|
@@ -109,6 +104,7 @@ define(["require", "exports", "../annotation/inject", "../constants/error_msgs",
|
|
|
109
104
|
return 0;
|
|
110
105
|
}
|
|
111
106
|
}
|
|
107
|
+
exports.getBaseClassDependencyCount = getBaseClassDependencyCount;
|
|
112
108
|
function formatTargetMetadata(targetMetadata) {
|
|
113
109
|
var targetMetadataMap = {};
|
|
114
110
|
targetMetadata.forEach(function (m) {
|
package/amd/planning/request.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
define(["require", "exports", "../utils/
|
|
1
|
+
define(["require", "exports", "../utils/id"], function (require, exports, id_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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/amd/planning/target.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
define(["require", "exports", "../constants/metadata_keys", "../utils/
|
|
1
|
+
define(["require", "exports", "../constants/metadata_keys", "../utils/id", "./metadata", "./queryable_string"], function (require, exports, METADATA_KEY, id_1, metadata_1, queryable_string_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
var Target = (function () {
|
|
5
5
|
function Target(type, name, serviceIdentifier, namedOrTagged) {
|
|
6
|
-
this.
|
|
6
|
+
this.id = id_1.id();
|
|
7
7
|
this.type = type;
|
|
8
8
|
this.serviceIdentifier = serviceIdentifier;
|
|
9
9
|
this.name = new queryable_string_1.QueryableString(name || "");
|
|
@@ -43,8 +43,8 @@ define(["require", "exports", "../constants/error_msgs", "../constants/literal_t
|
|
|
43
43
|
}
|
|
44
44
|
if (isRequestSingleton &&
|
|
45
45
|
requestScope !== null &&
|
|
46
|
-
requestScope.has(binding_1.
|
|
47
|
-
return requestScope.get(binding_1.
|
|
46
|
+
requestScope.has(binding_1.id)) {
|
|
47
|
+
return requestScope.get(binding_1.id);
|
|
48
48
|
}
|
|
49
49
|
if (binding_1.type === literal_types_1.BindingTypeEnum.ConstantValue) {
|
|
50
50
|
result = binding_1.cache;
|
|
@@ -80,8 +80,8 @@ define(["require", "exports", "../constants/error_msgs", "../constants/literal_t
|
|
|
80
80
|
}
|
|
81
81
|
if (isRequestSingleton &&
|
|
82
82
|
requestScope !== null &&
|
|
83
|
-
!requestScope.has(binding_1.
|
|
84
|
-
requestScope.set(binding_1.
|
|
83
|
+
!requestScope.has(binding_1.id)) {
|
|
84
|
+
requestScope.set(binding_1.id, result);
|
|
85
85
|
}
|
|
86
86
|
return result;
|
|
87
87
|
}
|
package/amd/utils/id.js
ADDED
|
@@ -16,11 +16,11 @@ export declare const INVALID_MIDDLEWARE_RETURN = "Invalid return type in middlew
|
|
|
16
16
|
export declare const INVALID_FUNCTION_BINDING = "Value provided to function binding must be a function!";
|
|
17
17
|
export declare const INVALID_TO_SELF_VALUE: string;
|
|
18
18
|
export declare const INVALID_DECORATOR_OPERATION: string;
|
|
19
|
-
export declare const
|
|
20
|
-
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;
|
|
21
20
|
export declare const CONTAINER_OPTIONS_MUST_BE_AN_OBJECT: string;
|
|
22
21
|
export declare const CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE: string;
|
|
23
22
|
export declare const CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE: string;
|
|
23
|
+
export declare const CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK: string;
|
|
24
24
|
export declare const MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
|
|
25
25
|
export declare const POST_CONSTRUCT_ERROR: (...values: any[]) => string;
|
|
26
26
|
export declare const CIRCULAR_DEPENDENCY_IN_FACTORY: (...values: any[]) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { interfaces } from "../interfaces/interfaces";
|
|
2
2
|
declare class Container implements interfaces.Container {
|
|
3
|
-
|
|
3
|
+
id: number;
|
|
4
4
|
parent: interfaces.Container | null;
|
|
5
5
|
readonly options: interfaces.ContainerOptions;
|
|
6
6
|
private _middleware;
|
|
@@ -21,7 +21,7 @@ declare class Container implements interfaces.Container {
|
|
|
21
21
|
isBoundTagged(serviceIdentifier: interfaces.ServiceIdentifier<any>, key: string | number | symbol, value: any): boolean;
|
|
22
22
|
snapshot(): void;
|
|
23
23
|
restore(): void;
|
|
24
|
-
createChild(): Container;
|
|
24
|
+
createChild(containerOptions?: interfaces.ContainerOptions): Container;
|
|
25
25
|
applyMiddleware(...middlewares: interfaces.Middleware[]): void;
|
|
26
26
|
applyCustomMetadataReader(metadataReader: interfaces.MetadataReader): void;
|
|
27
27
|
get<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { interfaces } from "../interfaces/interfaces";
|
|
2
2
|
export declare class ContainerModule implements interfaces.ContainerModule {
|
|
3
|
-
|
|
3
|
+
id: number;
|
|
4
4
|
registry: interfaces.ContainerModuleCallBack;
|
|
5
5
|
constructor(registry: interfaces.ContainerModuleCallBack);
|
|
6
6
|
}
|
|
7
7
|
export declare class AsyncContainerModule implements interfaces.AsyncContainerModule {
|
|
8
|
-
|
|
8
|
+
id: number;
|
|
9
9
|
registry: interfaces.AsyncContainerModuleCallBack;
|
|
10
10
|
constructor(registry: interfaces.AsyncContainerModuleCallBack);
|
|
11
11
|
}
|
|
@@ -33,7 +33,7 @@ declare namespace interfaces {
|
|
|
33
33
|
clone(): T;
|
|
34
34
|
}
|
|
35
35
|
interface Binding<T> extends Clonable<Binding<T>> {
|
|
36
|
-
|
|
36
|
+
id: number;
|
|
37
37
|
moduleId: string;
|
|
38
38
|
activated: boolean;
|
|
39
39
|
serviceIdentifier: ServiceIdentifier<T>;
|
|
@@ -64,7 +64,7 @@ declare namespace interfaces {
|
|
|
64
64
|
type Middleware = (next: Next) => Next;
|
|
65
65
|
type ContextInterceptor = (context: interfaces.Context) => interfaces.Context;
|
|
66
66
|
interface Context {
|
|
67
|
-
|
|
67
|
+
id: number;
|
|
68
68
|
container: Container;
|
|
69
69
|
plan: Plan;
|
|
70
70
|
currentRequest: Request;
|
|
@@ -92,7 +92,7 @@ declare namespace interfaces {
|
|
|
92
92
|
type ResolveRequestHandler = (request: interfaces.Request) => any;
|
|
93
93
|
type RequestScope = Map<any, any> | null;
|
|
94
94
|
interface Request {
|
|
95
|
-
|
|
95
|
+
id: number;
|
|
96
96
|
serviceIdentifier: ServiceIdentifier<any>;
|
|
97
97
|
parentContext: Context;
|
|
98
98
|
parentRequest: Request | null;
|
|
@@ -103,7 +103,7 @@ declare namespace interfaces {
|
|
|
103
103
|
addChildRequest(serviceIdentifier: ServiceIdentifier<any>, bindings: (Binding<any> | Binding<any>[]), target: Target): Request;
|
|
104
104
|
}
|
|
105
105
|
interface Target {
|
|
106
|
-
|
|
106
|
+
id: number;
|
|
107
107
|
serviceIdentifier: ServiceIdentifier<any>;
|
|
108
108
|
type: TargetType;
|
|
109
109
|
name: QueryableString;
|
|
@@ -122,9 +122,10 @@ 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
|
+
id: number;
|
|
128
129
|
parent: Container | null;
|
|
129
130
|
options: ContainerOptions;
|
|
130
131
|
bind<T>(serviceIdentifier: ServiceIdentifier<T>): BindingToSyntax<T>;
|
|
@@ -153,11 +154,11 @@ declare namespace interfaces {
|
|
|
153
154
|
type Unbind = <T>(serviceIdentifier: ServiceIdentifier<T>) => void;
|
|
154
155
|
type IsBound = <T>(serviceIdentifier: ServiceIdentifier<T>) => boolean;
|
|
155
156
|
interface ContainerModule {
|
|
156
|
-
|
|
157
|
+
id: number;
|
|
157
158
|
registry: ContainerModuleCallBack;
|
|
158
159
|
}
|
|
159
160
|
interface AsyncContainerModule {
|
|
160
|
-
|
|
161
|
+
id: number;
|
|
161
162
|
registry: AsyncContainerModuleCallBack;
|
|
162
163
|
}
|
|
163
164
|
type ContainerModuleCallBack = (bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => void;
|
package/dts/inversify.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ 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";
|
|
@@ -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 { interfaces } from "./interfaces/interfaces";
|
|
18
18
|
export { decorate } from "./annotation/decorator_utils";
|
|
19
19
|
export { traverseAncerstors, taggedConstraint, namedConstraint, typeConstraint } from "./syntax/constraint_helpers";
|
|
@@ -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 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { interfaces } from "../interfaces/interfaces";
|
|
2
2
|
declare class Request implements interfaces.Request {
|
|
3
|
-
|
|
3
|
+
id: number;
|
|
4
4
|
serviceIdentifier: interfaces.ServiceIdentifier<any>;
|
|
5
5
|
parentContext: interfaces.Context;
|
|
6
6
|
parentRequest: interfaces.Request | null;
|
package/dts/planning/target.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { interfaces } from "../interfaces/interfaces";
|
|
2
2
|
import { Metadata } from "./metadata";
|
|
3
3
|
declare class Target implements interfaces.Target {
|
|
4
|
-
|
|
4
|
+
id: number;
|
|
5
5
|
type: interfaces.TargetType;
|
|
6
6
|
serviceIdentifier: interfaces.ServiceIdentifier<any>;
|
|
7
7
|
name: interfaces.QueryableString;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function template(strings: TemplateStringsArray, ...keys: any[]): (...values: any[]) => string;
|
|
@@ -26,7 +26,7 @@ function _tagParameterOrProperty(metadataKey, annotationTarget, propertyName, me
|
|
|
26
26
|
for (var _i = 0, paramOrPropertyMetadata_1 = paramOrPropertyMetadata; _i < paramOrPropertyMetadata_1.length; _i++) {
|
|
27
27
|
var m = paramOrPropertyMetadata_1[_i];
|
|
28
28
|
if (m.key === metadata.key) {
|
|
29
|
-
throw new Error(ERROR_MSGS.DUPLICATED_METADATA + " " + m.key);
|
|
29
|
+
throw new Error(ERROR_MSGS.DUPLICATED_METADATA + " " + m.key.toString());
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
}
|
package/es/bindings/binding.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BindingTypeEnum } from "../constants/literal_types";
|
|
2
|
-
import {
|
|
2
|
+
import { id } from "../utils/id";
|
|
3
3
|
var Binding = (function () {
|
|
4
4
|
function Binding(serviceIdentifier, scope) {
|
|
5
|
-
this.
|
|
5
|
+
this.id = id();
|
|
6
6
|
this.activated = false;
|
|
7
7
|
this.serviceIdentifier = serviceIdentifier;
|
|
8
8
|
this.scope = scope;
|