inversify 4.10.0 → 4.14.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.
Files changed (57) hide show
  1. package/.auditignore +2 -0
  2. package/README.md +5 -5
  3. package/amd/annotation/decorator_utils.js +1 -1
  4. package/amd/bindings/binding.js +2 -2
  5. package/amd/constants/error_msgs.js +10 -2
  6. package/amd/container/container.js +142 -68
  7. package/amd/container/container_module.js +10 -2
  8. package/amd/inversify.js +3 -2
  9. package/amd/planning/context.js +2 -2
  10. package/amd/planning/planner.js +7 -0
  11. package/amd/planning/reflection_utils.js +2 -6
  12. package/amd/planning/request.js +2 -2
  13. package/amd/planning/target.js +2 -2
  14. package/amd/resolution/resolver.js +4 -4
  15. package/amd/utils/id.js +9 -0
  16. package/dts/bindings/binding.d.ts +1 -1
  17. package/dts/constants/error_msgs.d.ts +2 -2
  18. package/dts/container/container.d.ts +4 -2
  19. package/dts/container/container_module.d.ts +7 -3
  20. package/dts/interfaces/interfaces.d.ts +13 -6
  21. package/dts/inversify.d.ts +2 -2
  22. package/dts/planning/context.d.ts +1 -1
  23. package/dts/planning/reflection_utils.d.ts +3 -1
  24. package/dts/planning/request.d.ts +1 -1
  25. package/dts/planning/target.d.ts +1 -1
  26. package/dts/utils/id.d.ts +2 -0
  27. package/dts/utils/template.d.ts +1 -0
  28. package/es/annotation/decorator_utils.js +1 -1
  29. package/es/bindings/binding.js +2 -2
  30. package/es/constants/error_msgs.js +10 -2
  31. package/es/container/container.js +142 -68
  32. package/es/container/container_module.js +10 -2
  33. package/es/inversify.js +2 -2
  34. package/es/planning/context.js +2 -2
  35. package/es/planning/planner.js +8 -1
  36. package/es/planning/reflection_utils.js +1 -7
  37. package/es/planning/request.js +2 -2
  38. package/es/planning/target.js +2 -2
  39. package/es/resolution/resolver.js +4 -4
  40. package/es/utils/id.js +5 -0
  41. package/lib/annotation/decorator_utils.js +1 -1
  42. package/lib/bindings/binding.js +2 -2
  43. package/lib/constants/error_msgs.js +10 -2
  44. package/lib/container/container.js +142 -68
  45. package/lib/container/container_module.js +10 -2
  46. package/lib/inversify.js +3 -2
  47. package/lib/planning/context.js +2 -2
  48. package/lib/planning/planner.js +7 -0
  49. package/lib/planning/reflection_utils.js +2 -6
  50. package/lib/planning/request.js +2 -2
  51. package/lib/planning/target.js +2 -2
  52. package/lib/resolution/resolver.js +4 -4
  53. package/lib/utils/id.js +7 -0
  54. package/package.json +20 -20
  55. package/amd/utils/guid.js +0 -14
  56. package/es/utils/guid.js +0 -10
  57. package/lib/utils/guid.js +0 -12
package/.auditignore ADDED
@@ -0,0 +1,2 @@
1
+ https://nodesecurity.io/advisories/118
2
+ https://nodesecurity.io/advisories/577
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 (4KB) inversion of control (IoC) container for TypeScript and JavaScript apps.
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
  }
@@ -1,9 +1,9 @@
1
- define(["require", "exports", "../constants/literal_types", "../utils/guid"], function (require, exports, literal_types_1, guid_1) {
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.guid = guid_1.guid();
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.ARGUMENTS_LENGTH_MISMATCH_1 = "The number of constructor arguments in the derived class ";
29
- exports.ARGUMENTS_LENGTH_MISMATCH_2 = " must be >= than the number of constructor arguments of its base class.";
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 = [];
@@ -1,36 +1,73 @@
1
- define(["require", "exports", "../bindings/binding", "../constants/error_msgs", "../constants/literal_types", "../constants/metadata_keys", "../planning/metadata_reader", "../planning/planner", "../resolution/resolver", "../syntax/binding_to_syntax", "../utils/guid", "../utils/serialization", "./container_snapshot", "./lookup"], function (require, exports, binding_1, ERROR_MSGS, literal_types_1, METADATA_KEY, metadata_reader_1, planner_1, resolver_1, binding_to_syntax_1, guid_1, serialization_1, container_snapshot_1, lookup_1) {
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
+ };
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) {
2
37
  "use strict";
3
38
  Object.defineProperty(exports, "__esModule", { value: true });
4
39
  var Container = (function () {
5
40
  function Container(containerOptions) {
6
- if (containerOptions !== undefined) {
7
- if (typeof containerOptions !== "object") {
8
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
9
- }
10
- else {
11
- if (containerOptions.defaultScope !== undefined &&
12
- containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
13
- containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
14
- containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
15
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
16
- }
17
- if (containerOptions.autoBindInjectable !== undefined &&
18
- typeof containerOptions.autoBindInjectable !== "boolean") {
19
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
20
- }
21
- }
22
- this.options = {
23
- autoBindInjectable: containerOptions.autoBindInjectable,
24
- defaultScope: containerOptions.defaultScope
25
- };
41
+ var options = containerOptions || {};
42
+ if (typeof options !== "object") {
43
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
26
44
  }
27
- else {
28
- this.options = {
29
- autoBindInjectable: false,
30
- defaultScope: literal_types_1.BindingScopeEnum.Transient
31
- };
45
+ if (options.defaultScope === undefined) {
46
+ options.defaultScope = literal_types_1.BindingScopeEnum.Transient;
47
+ }
48
+ else if (options.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
49
+ options.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
50
+ options.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
51
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
52
+ }
53
+ if (options.autoBindInjectable === undefined) {
54
+ options.autoBindInjectable = false;
32
55
  }
33
- this.guid = guid_1.guid();
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();
34
71
  this._bindingDictionary = new lookup_1.Lookup();
35
72
  this._snapshots = [];
36
73
  this._middleware = null;
@@ -54,46 +91,44 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
54
91
  return container;
55
92
  };
56
93
  Container.prototype.load = function () {
57
- var _this = this;
58
94
  var modules = [];
59
95
  for (var _i = 0; _i < arguments.length; _i++) {
60
96
  modules[_i] = arguments[_i];
61
97
  }
62
- var setModuleId = function (bindingToSyntax, moduleId) {
63
- bindingToSyntax._binding.moduleId = moduleId;
64
- };
65
- var getBindFunction = function (moduleId) {
66
- return function (serviceIdentifier) {
67
- var bindingToSyntax = _this.bind.call(_this, serviceIdentifier);
68
- setModuleId(bindingToSyntax, moduleId);
69
- return bindingToSyntax;
70
- };
71
- };
72
- var getUnbindFunction = function (moduleId) {
73
- return function (serviceIdentifier) {
74
- var _unbind = _this.unbind.bind(_this);
75
- _unbind(serviceIdentifier);
76
- };
77
- };
78
- var getIsboundFunction = function (moduleId) {
79
- return function (serviceIdentifier) {
80
- var _isBound = _this.isBound.bind(_this);
81
- return _isBound(serviceIdentifier);
82
- };
83
- };
84
- var getRebindFunction = function (moduleId) {
85
- return function (serviceIdentifier) {
86
- var bindingToSyntax = _this.rebind.call(_this, serviceIdentifier);
87
- setModuleId(bindingToSyntax, moduleId);
88
- return bindingToSyntax;
89
- };
90
- };
91
- modules.forEach(function (module) {
92
- var bindFunction = getBindFunction(module.guid);
93
- var unbindFunction = getUnbindFunction(module.guid);
94
- var isboundFunction = getIsboundFunction(module.guid);
95
- var rebindFunction = getRebindFunction(module.guid);
96
- module.registry(bindFunction, unbindFunction, isboundFunction, rebindFunction);
98
+ var getHelpers = this._getContainerModuleHelpersFactory();
99
+ for (var _a = 0, modules_1 = modules; _a < modules_1.length; _a++) {
100
+ var currentModule = modules_1[_a];
101
+ var containerModuleHelpers = getHelpers(currentModule.id);
102
+ currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction);
103
+ }
104
+ };
105
+ Container.prototype.loadAsync = function () {
106
+ var modules = [];
107
+ for (var _i = 0; _i < arguments.length; _i++) {
108
+ modules[_i] = arguments[_i];
109
+ }
110
+ return __awaiter(this, void 0, void 0, function () {
111
+ var getHelpers, _a, modules_2, currentModule, containerModuleHelpers;
112
+ return __generator(this, function (_b) {
113
+ switch (_b.label) {
114
+ case 0:
115
+ getHelpers = this._getContainerModuleHelpersFactory();
116
+ _a = 0, modules_2 = modules;
117
+ _b.label = 1;
118
+ case 1:
119
+ if (!(_a < modules_2.length)) return [3, 4];
120
+ currentModule = modules_2[_a];
121
+ containerModuleHelpers = getHelpers(currentModule.id);
122
+ return [4, currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction)];
123
+ case 2:
124
+ _b.sent();
125
+ _b.label = 3;
126
+ case 3:
127
+ _a++;
128
+ return [3, 1];
129
+ case 4: return [2];
130
+ }
131
+ });
97
132
  });
98
133
  };
99
134
  Container.prototype.unload = function () {
@@ -106,7 +141,7 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
106
141
  return item.moduleId === expected;
107
142
  }; };
108
143
  modules.forEach(function (module) {
109
- var condition = conditionFactory(module.guid);
144
+ var condition = conditionFactory(module.id);
110
145
  _this._bindingDictionary.removeByCondition(condition);
111
146
  });
112
147
  };
@@ -164,8 +199,8 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
164
199
  this._bindingDictionary = snapshot.bindings;
165
200
  this._middleware = snapshot.middleware;
166
201
  };
167
- Container.prototype.createChild = function () {
168
- var child = new Container();
202
+ Container.prototype.createChild = function (containerOptions) {
203
+ var child = new Container(containerOptions || this.options);
169
204
  child.parent = this;
170
205
  return child;
171
206
  };
@@ -199,11 +234,50 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
199
234
  return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
200
235
  };
201
236
  Container.prototype.resolve = function (constructorFunction) {
202
- var tempContainer = new Container();
237
+ var tempContainer = this.createChild();
203
238
  tempContainer.bind(constructorFunction).toSelf();
204
- tempContainer.parent = this;
205
239
  return tempContainer.get(constructorFunction);
206
240
  };
241
+ Container.prototype._getContainerModuleHelpersFactory = function () {
242
+ var _this = this;
243
+ var setModuleId = function (bindingToSyntax, moduleId) {
244
+ bindingToSyntax._binding.moduleId = moduleId;
245
+ };
246
+ var getBindFunction = function (moduleId) {
247
+ return function (serviceIdentifier) {
248
+ var _bind = _this.bind.bind(_this);
249
+ var bindingToSyntax = _bind(serviceIdentifier);
250
+ setModuleId(bindingToSyntax, moduleId);
251
+ return bindingToSyntax;
252
+ };
253
+ };
254
+ var getUnbindFunction = function (moduleId) {
255
+ return function (serviceIdentifier) {
256
+ var _unbind = _this.unbind.bind(_this);
257
+ _unbind(serviceIdentifier);
258
+ };
259
+ };
260
+ var getIsboundFunction = function (moduleId) {
261
+ return function (serviceIdentifier) {
262
+ var _isBound = _this.isBound.bind(_this);
263
+ return _isBound(serviceIdentifier);
264
+ };
265
+ };
266
+ var getRebindFunction = function (moduleId) {
267
+ return function (serviceIdentifier) {
268
+ var _rebind = _this.rebind.bind(_this);
269
+ var bindingToSyntax = _rebind(serviceIdentifier);
270
+ setModuleId(bindingToSyntax, moduleId);
271
+ return bindingToSyntax;
272
+ };
273
+ };
274
+ return function (mId) { return ({
275
+ bindFunction: getBindFunction(mId),
276
+ isboundFunction: getIsboundFunction(mId),
277
+ rebindFunction: getRebindFunction(mId),
278
+ unbindFunction: getUnbindFunction(mId)
279
+ }); };
280
+ };
207
281
  Container.prototype._get = function (avoidConstraints, isMultiInject, targetType, serviceIdentifier, key, value) {
208
282
  var result = null;
209
283
  var defaultArgs = {
@@ -1,12 +1,20 @@
1
- define(["require", "exports", "../utils/guid"], function (require, exports, guid_1) {
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.guid = guid_1.guid();
6
+ this.id = id_1.id();
7
7
  this.registry = registry;
8
8
  }
9
9
  return ContainerModule;
10
10
  }());
11
11
  exports.ContainerModule = ContainerModule;
12
+ var AsyncContainerModule = (function () {
13
+ function AsyncContainerModule(registry) {
14
+ this.id = id_1.id();
15
+ this.registry = registry;
16
+ }
17
+ return AsyncContainerModule;
18
+ }());
19
+ exports.AsyncContainerModule = AsyncContainerModule;
12
20
  });
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/guid", "./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, guid_1, decorator_utils_1, constraint_helpers_1, serialization_1, binding_utils_1) {
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.guid = guid_1.guid;
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;
@@ -1,9 +1,9 @@
1
- define(["require", "exports", "../utils/guid"], function (require, exports, guid_1) {
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.guid = guid_1.guid();
6
+ this.id = id_1.id();
7
7
  this.container = container;
8
8
  }
9
9
  Context.prototype.addPlan = function (plan) {
@@ -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) {
@@ -1,9 +1,9 @@
1
- define(["require", "exports", "../utils/guid"], function (require, exports, guid_1) {
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.guid = guid_1.guid();
6
+ this.id = id_1.id();
7
7
  this.serviceIdentifier = serviceIdentifier;
8
8
  this.parentContext = parentContext;
9
9
  this.parentRequest = parentRequest;
@@ -1,9 +1,9 @@
1
- define(["require", "exports", "../constants/metadata_keys", "../utils/guid", "./metadata", "./queryable_string"], function (require, exports, METADATA_KEY, guid_1, metadata_1, queryable_string_1) {
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.guid = guid_1.guid();
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.guid)) {
47
- return requestScope.get(binding_1.guid);
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.guid)) {
84
- requestScope.set(binding_1.guid, result);
83
+ !requestScope.has(binding_1.id)) {
84
+ requestScope.set(binding_1.id, result);
85
85
  }
86
86
  return result;
87
87
  }
@@ -0,0 +1,9 @@
1
+ define(["require", "exports"], function (require, exports) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ var idCounter = 0;
5
+ function id() {
6
+ return idCounter++;
7
+ }
8
+ exports.id = id;
9
+ });
@@ -1,6 +1,6 @@
1
1
  import { interfaces } from "../interfaces/interfaces";
2
2
  declare class Binding<T> implements interfaces.Binding<T> {
3
- guid: string;
3
+ id: number;
4
4
  moduleId: string;
5
5
  activated: boolean;
6
6
  serviceIdentifier: interfaces.ServiceIdentifier<T>;
@@ -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 ARGUMENTS_LENGTH_MISMATCH_1 = "The number of constructor arguments in the derived class ";
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
- guid: string;
3
+ id: number;
4
4
  parent: interfaces.Container | null;
5
5
  readonly options: interfaces.ContainerOptions;
6
6
  private _middleware;
@@ -10,6 +10,7 @@ declare class Container implements interfaces.Container {
10
10
  static merge(container1: interfaces.Container, container2: interfaces.Container): interfaces.Container;
11
11
  constructor(containerOptions?: interfaces.ContainerOptions);
12
12
  load(...modules: interfaces.ContainerModule[]): void;
13
+ loadAsync(...modules: interfaces.AsyncContainerModule[]): Promise<void>;
13
14
  unload(...modules: interfaces.ContainerModule[]): void;
14
15
  bind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T>;
15
16
  rebind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T>;
@@ -20,7 +21,7 @@ declare class Container implements interfaces.Container {
20
21
  isBoundTagged(serviceIdentifier: interfaces.ServiceIdentifier<any>, key: string | number | symbol, value: any): boolean;
21
22
  snapshot(): void;
22
23
  restore(): void;
23
- createChild(): Container;
24
+ createChild(containerOptions?: interfaces.ContainerOptions): Container;
24
25
  applyMiddleware(...middlewares: interfaces.Middleware[]): void;
25
26
  applyCustomMetadataReader(metadataReader: interfaces.MetadataReader): void;
26
27
  get<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T;
@@ -30,6 +31,7 @@ declare class Container implements interfaces.Container {
30
31
  getAllTagged<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: any): T[];
31
32
  getAllNamed<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): T[];
32
33
  resolve<T>(constructorFunction: interfaces.Newable<T>): T;
34
+ private _getContainerModuleHelpersFactory();
33
35
  private _get<T>(avoidConstraints, isMultiInject, targetType, serviceIdentifier, key?, value?);
34
36
  private _planAndResolve<T>();
35
37
  }
@@ -1,7 +1,11 @@
1
1
  import { interfaces } from "../interfaces/interfaces";
2
- declare class ContainerModule implements interfaces.ContainerModule {
3
- guid: string;
2
+ export declare class ContainerModule implements interfaces.ContainerModule {
3
+ id: number;
4
4
  registry: interfaces.ContainerModuleCallBack;
5
5
  constructor(registry: interfaces.ContainerModuleCallBack);
6
6
  }
7
- export { ContainerModule };
7
+ export declare class AsyncContainerModule implements interfaces.AsyncContainerModule {
8
+ id: number;
9
+ registry: interfaces.AsyncContainerModuleCallBack;
10
+ constructor(registry: interfaces.AsyncContainerModuleCallBack);
11
+ }