inversify 4.9.0 → 4.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,39 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [0, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
2
37
  Object.defineProperty(exports, "__esModule", { value: true });
3
38
  var binding_1 = require("../bindings/binding");
4
39
  var ERROR_MSGS = require("../constants/error_msgs");
@@ -14,33 +49,35 @@ var container_snapshot_1 = require("./container_snapshot");
14
49
  var lookup_1 = require("./lookup");
15
50
  var Container = (function () {
16
51
  function Container(containerOptions) {
17
- if (containerOptions !== undefined) {
18
- if (typeof containerOptions !== "object") {
19
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
20
- }
21
- else {
22
- if (containerOptions.defaultScope !== undefined &&
23
- containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
24
- containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
25
- containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
26
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
27
- }
28
- if (containerOptions.autoBindInjectable !== undefined &&
29
- typeof containerOptions.autoBindInjectable !== "boolean") {
30
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
31
- }
32
- }
33
- this.options = {
34
- autoBindInjectable: containerOptions.autoBindInjectable,
35
- defaultScope: containerOptions.defaultScope
36
- };
52
+ var options = containerOptions || {};
53
+ if (typeof options !== "object") {
54
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
37
55
  }
38
- else {
39
- this.options = {
40
- autoBindInjectable: false,
41
- defaultScope: literal_types_1.BindingScopeEnum.Transient
42
- };
56
+ if (options.defaultScope === undefined) {
57
+ options.defaultScope = literal_types_1.BindingScopeEnum.Transient;
58
+ }
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;
43
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
+ };
44
81
  this.guid = guid_1.guid();
45
82
  this._bindingDictionary = new lookup_1.Lookup();
46
83
  this._snapshots = [];
@@ -65,46 +102,44 @@ var Container = (function () {
65
102
  return container;
66
103
  };
67
104
  Container.prototype.load = function () {
68
- var _this = this;
69
105
  var modules = [];
70
106
  for (var _i = 0; _i < arguments.length; _i++) {
71
107
  modules[_i] = arguments[_i];
72
108
  }
73
- var setModuleId = function (bindingToSyntax, moduleId) {
74
- bindingToSyntax._binding.moduleId = moduleId;
75
- };
76
- var getBindFunction = function (moduleId) {
77
- return function (serviceIdentifier) {
78
- var bindingToSyntax = _this.bind.call(_this, serviceIdentifier);
79
- setModuleId(bindingToSyntax, moduleId);
80
- return bindingToSyntax;
81
- };
82
- };
83
- var getUnbindFunction = function (moduleId) {
84
- return function (serviceIdentifier) {
85
- var _unbind = _this.unbind.bind(_this);
86
- _unbind(serviceIdentifier);
87
- };
88
- };
89
- var getIsboundFunction = function (moduleId) {
90
- return function (serviceIdentifier) {
91
- var _isBound = _this.isBound.bind(_this);
92
- return _isBound(serviceIdentifier);
93
- };
94
- };
95
- var getRebindFunction = function (moduleId) {
96
- return function (serviceIdentifier) {
97
- var bindingToSyntax = _this.rebind.call(_this, serviceIdentifier);
98
- setModuleId(bindingToSyntax, moduleId);
99
- return bindingToSyntax;
100
- };
101
- };
102
- modules.forEach(function (module) {
103
- var bindFunction = getBindFunction(module.guid);
104
- var unbindFunction = getUnbindFunction(module.guid);
105
- var isboundFunction = getIsboundFunction(module.guid);
106
- var rebindFunction = getRebindFunction(module.guid);
107
- module.registry(bindFunction, unbindFunction, isboundFunction, rebindFunction);
109
+ var getHelpers = this._getContainerModuleHelpersFactory();
110
+ for (var _a = 0, modules_1 = modules; _a < modules_1.length; _a++) {
111
+ var currentModule = modules_1[_a];
112
+ var containerModuleHelpers = getHelpers(currentModule.guid);
113
+ currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction);
114
+ }
115
+ };
116
+ Container.prototype.loadAsync = function () {
117
+ var modules = [];
118
+ for (var _i = 0; _i < arguments.length; _i++) {
119
+ modules[_i] = arguments[_i];
120
+ }
121
+ return __awaiter(this, void 0, void 0, function () {
122
+ var getHelpers, _a, modules_2, currentModule, containerModuleHelpers;
123
+ return __generator(this, function (_b) {
124
+ switch (_b.label) {
125
+ case 0:
126
+ getHelpers = this._getContainerModuleHelpersFactory();
127
+ _a = 0, modules_2 = modules;
128
+ _b.label = 1;
129
+ case 1:
130
+ if (!(_a < modules_2.length)) return [3, 4];
131
+ currentModule = modules_2[_a];
132
+ containerModuleHelpers = getHelpers(currentModule.guid);
133
+ return [4, currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction)];
134
+ case 2:
135
+ _b.sent();
136
+ _b.label = 3;
137
+ case 3:
138
+ _a++;
139
+ return [3, 1];
140
+ case 4: return [2];
141
+ }
142
+ });
108
143
  });
109
144
  };
110
145
  Container.prototype.unload = function () {
@@ -175,8 +210,8 @@ var Container = (function () {
175
210
  this._bindingDictionary = snapshot.bindings;
176
211
  this._middleware = snapshot.middleware;
177
212
  };
178
- Container.prototype.createChild = function () {
179
- var child = new Container();
213
+ Container.prototype.createChild = function (containerOptions) {
214
+ var child = new Container(containerOptions);
180
215
  child.parent = this;
181
216
  return child;
182
217
  };
@@ -215,6 +250,46 @@ var Container = (function () {
215
250
  tempContainer.parent = this;
216
251
  return tempContainer.get(constructorFunction);
217
252
  };
253
+ Container.prototype._getContainerModuleHelpersFactory = function () {
254
+ var _this = this;
255
+ var setModuleId = function (bindingToSyntax, moduleId) {
256
+ bindingToSyntax._binding.moduleId = moduleId;
257
+ };
258
+ var getBindFunction = function (moduleId) {
259
+ return function (serviceIdentifier) {
260
+ var _bind = _this.bind.bind(_this);
261
+ var bindingToSyntax = _bind(serviceIdentifier);
262
+ setModuleId(bindingToSyntax, moduleId);
263
+ return bindingToSyntax;
264
+ };
265
+ };
266
+ var getUnbindFunction = function (moduleId) {
267
+ return function (serviceIdentifier) {
268
+ var _unbind = _this.unbind.bind(_this);
269
+ _unbind(serviceIdentifier);
270
+ };
271
+ };
272
+ var getIsboundFunction = function (moduleId) {
273
+ return function (serviceIdentifier) {
274
+ var _isBound = _this.isBound.bind(_this);
275
+ return _isBound(serviceIdentifier);
276
+ };
277
+ };
278
+ var getRebindFunction = function (moduleId) {
279
+ return function (serviceIdentifier) {
280
+ var _rebind = _this.rebind.bind(_this);
281
+ var bindingToSyntax = _rebind(serviceIdentifier);
282
+ setModuleId(bindingToSyntax, moduleId);
283
+ return bindingToSyntax;
284
+ };
285
+ };
286
+ return function (mId) { return ({
287
+ bindFunction: getBindFunction(mId),
288
+ isboundFunction: getIsboundFunction(mId),
289
+ rebindFunction: getRebindFunction(mId),
290
+ unbindFunction: getUnbindFunction(mId)
291
+ }); };
292
+ };
218
293
  Container.prototype._get = function (avoidConstraints, isMultiInject, targetType, serviceIdentifier, key, value) {
219
294
  var result = null;
220
295
  var defaultArgs = {
@@ -9,3 +9,11 @@ var ContainerModule = (function () {
9
9
  return ContainerModule;
10
10
  }());
11
11
  exports.ContainerModule = ContainerModule;
12
+ var AsyncContainerModule = (function () {
13
+ function AsyncContainerModule(registry) {
14
+ this.guid = guid_1.guid();
15
+ this.registry = registry;
16
+ }
17
+ return AsyncContainerModule;
18
+ }());
19
+ exports.AsyncContainerModule = AsyncContainerModule;
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;
@@ -18,6 +19,7 @@ var named_1 = require("./annotation/named");
18
19
  exports.named = named_1.named;
19
20
  var inject_1 = require("./annotation/inject");
20
21
  exports.inject = inject_1.inject;
22
+ exports.LazyServiceIdentifer = inject_1.LazyServiceIdentifer;
21
23
  var optional_1 = require("./annotation/optional");
22
24
  exports.optional = optional_1.optional;
23
25
  var unmanaged_1 = require("./annotation/unmanaged");
@@ -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
  });
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ var inject_1 = require("../annotation/inject");
3
4
  var ERROR_MSGS = require("../constants/error_msgs");
4
5
  var literal_types_1 = require("../constants/literal_types");
5
6
  var METADATA_KEY = require("../constants/metadata_keys");
6
7
  var serialization_1 = require("../utils/serialization");
8
+ exports.getFunctionName = serialization_1.getFunctionName;
7
9
  var target_1 = require("./target");
8
10
  function getDependencies(metadataReader, func) {
9
11
  var constructorName = serialization_1.getFunctionName(func);
@@ -25,12 +27,6 @@ function getTargets(metadataReader, constructorName, func, isBaseClass) {
25
27
  var constructorTargets = getConstructorArgsAsTargets(isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata, iterations);
26
28
  var propertyTargets = getClassPropsAsTargets(metadataReader, func);
27
29
  var targets = constructorTargets.concat(propertyTargets);
28
- var baseClassDependencyCount = getBaseClassDependencyCount(metadataReader, func);
29
- if (targets.length < baseClassDependencyCount) {
30
- var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_1 +
31
- constructorName + ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_2;
32
- throw new Error(error);
33
- }
34
30
  return targets;
35
31
  }
36
32
  function getConstructorArgsAsTarget(index, isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata) {
@@ -40,6 +36,9 @@ function getConstructorArgsAsTarget(index, isBaseClass, constructorName, service
40
36
  var serviceIdentifier = serviceIdentifiers[index];
41
37
  var injectIdentifier = (metadata.inject || metadata.multiInject);
42
38
  serviceIdentifier = (injectIdentifier) ? (injectIdentifier) : serviceIdentifier;
39
+ if (serviceIdentifier instanceof inject_1.LazyServiceIdentifer) {
40
+ serviceIdentifier = serviceIdentifier.unwrap();
41
+ }
43
42
  if (isManaged) {
44
43
  var isObject = serviceIdentifier === Object;
45
44
  var isFunction = serviceIdentifier === Function;
@@ -110,6 +109,7 @@ function getBaseClassDependencyCount(metadataReader, func) {
110
109
  return 0;
111
110
  }
112
111
  }
112
+ exports.getBaseClassDependencyCount = getBaseClassDependencyCount;
113
113
  function formatTargetMetadata(targetMetadata) {
114
114
  var targetMetadataMap = {};
115
115
  targetMetadata.forEach(function (m) {
package/package.json CHANGED
@@ -1,80 +1,80 @@
1
- {
2
- "name": "inversify",
3
- "version": "4.9.0",
4
- "description": "A powerful and lightweight inversion of control container for JavaScript and Node.js apps powered by TypeScript.",
5
- "main": "lib/inversify.js",
6
- "jsnext:main": "es/inversify.js",
7
- "types": "./dts/inversify.d.ts",
8
- "directories": {
9
- "test": "gulp"
10
- },
11
- "scripts": {
12
- "test": "gulp",
13
- "publish-please": "publish-please",
14
- "prepublish": "publish-please guard"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "https://github.com/inversify/InversifyJS.git"
19
- },
20
- "keywords": [
21
- "ioc",
22
- "di",
23
- "javascript",
24
- "typescript",
25
- "node",
26
- "dependency injection",
27
- "dependency inversion",
28
- "inversion of control container"
29
- ],
30
- "author": "Remo H. Jansen",
31
- "license": "MIT",
32
- "bugs": {
33
- "url": "https://github.com/inversify/InversifyJS/issues"
34
- },
35
- "homepage": "http://inversify.io",
36
- "engines": {},
37
- "devDependencies": {
38
- "@types/chai": "4.0.10",
39
- "@types/harmony-proxy": "1.0.29",
40
- "@types/mocha": " 2.2.44",
41
- "@types/sinon": "4.1.2",
42
- "bluebird": "3.5.1",
43
- "browserify": "14.5.0",
44
- "chai": "4.1.2",
45
- "del": "3.0.0",
46
- "es6-symbol": "3.1.1",
47
- "gulp": "3.9.1",
48
- "gulp-istanbul": "1.1.2",
49
- "gulp-mocha": "3.0.1",
50
- "gulp-rename": "1.2.2",
51
- "gulp-sourcemaps": "2.6.1",
52
- "gulp-tslint": "8.1.2",
53
- "gulp-typescript": "3.2.3",
54
- "gulp-uglify": "3.0.0",
55
- "harmonize": "2.0.0",
56
- "harmony-proxy": "1.0.1",
57
- "istanbul": "0.4.5",
58
- "karma": "1.7.1",
59
- "karma-chai": "0.1.0",
60
- "karma-chrome-launcher": "2.2.0",
61
- "karma-commonjs": "1.0.0",
62
- "karma-es6-shim": "1.0.0",
63
- "karma-firefox-launcher": "1.1.0",
64
- "karma-ie-launcher": "1.0.0",
65
- "karma-mocha": "1.3.0",
66
- "karma-mocha-reporter": "2.2.5",
67
- "karma-phantomjs-launcher": "1.0.4",
68
- "karma-sinon": "1.0.5",
69
- "mocha": "4.0.1",
70
- "performance-now": "2.1.0",
71
- "publish-please": "2.3.1",
72
- "reflect-metadata": "0.1.10",
73
- "run-sequence": "2.2.0",
74
- "sinon": "4.1.3",
75
- "tslint": "5.8.0",
76
- "typescript": "2.6.2",
77
- "vinyl-buffer": "1.0.0",
78
- "vinyl-source-stream": "1.1.0"
79
- }
80
- }
1
+ {
2
+ "name": "inversify",
3
+ "version": "4.13.0",
4
+ "description": "A powerful and lightweight inversion of control container for JavaScript and Node.js apps powered by TypeScript.",
5
+ "main": "lib/inversify.js",
6
+ "jsnext:main": "es/inversify.js",
7
+ "types": "./dts/inversify.d.ts",
8
+ "directories": {
9
+ "test": "gulp"
10
+ },
11
+ "scripts": {
12
+ "test": "gulp",
13
+ "publish-please": "publish-please",
14
+ "prepublish": "publish-please guard"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/inversify/InversifyJS.git"
19
+ },
20
+ "keywords": [
21
+ "ioc",
22
+ "di",
23
+ "javascript",
24
+ "typescript",
25
+ "node",
26
+ "dependency injection",
27
+ "dependency inversion",
28
+ "inversion of control container"
29
+ ],
30
+ "author": "Remo H. Jansen",
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/inversify/InversifyJS/issues"
34
+ },
35
+ "homepage": "http://inversify.io",
36
+ "engines": {},
37
+ "devDependencies": {
38
+ "@types/chai": "4.1.2",
39
+ "@types/harmony-proxy": "1.0.29",
40
+ "@types/mocha": "5.0.0",
41
+ "@types/sinon": "4.3.1",
42
+ "bluebird": "3.5.1",
43
+ "browserify": "16.2.0",
44
+ "chai": "4.1.2",
45
+ "del": "3.0.0",
46
+ "es6-symbol": "3.1.1",
47
+ "gulp": "3.9.1",
48
+ "gulp-istanbul": "1.1.3",
49
+ "gulp-mocha": "5.0.0",
50
+ "gulp-rename": "1.2.2",
51
+ "gulp-sourcemaps": "2.6.3",
52
+ "gulp-tslint": "8.1.3",
53
+ "gulp-typescript": "4.0.2",
54
+ "gulp-uglify": "3.0.0",
55
+ "harmonize": "2.0.0",
56
+ "harmony-proxy": "1.0.1",
57
+ "istanbul": "0.4.5",
58
+ "karma": "2.0.0",
59
+ "karma-chai": "0.1.0",
60
+ "karma-chrome-launcher": "2.2.0",
61
+ "karma-commonjs": "1.0.0",
62
+ "karma-es6-shim": "1.0.0",
63
+ "karma-firefox-launcher": "1.1.0",
64
+ "karma-ie-launcher": "1.0.0",
65
+ "karma-mocha": "1.3.0",
66
+ "karma-mocha-reporter": "2.2.5",
67
+ "karma-phantomjs-launcher": "1.0.4",
68
+ "karma-sinon": "1.0.5",
69
+ "mocha": "5.1.0",
70
+ "performance-now": "2.1.0",
71
+ "publish-please": "2.4.1",
72
+ "reflect-metadata": "0.1.12",
73
+ "run-sequence": "2.2.1",
74
+ "sinon": "5.0.0",
75
+ "tslint": "5.9.1",
76
+ "typescript": "2.6.2",
77
+ "vinyl-source-stream": "2.0.0",
78
+ "vinyl-buffer": "1.0.1"
79
+ }
80
+ }