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
@@ -33,7 +33,7 @@ declare namespace interfaces {
33
33
  clone(): T;
34
34
  }
35
35
  interface Binding<T> extends Clonable<Binding<T>> {
36
- guid: string;
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
- guid: string;
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
- guid: string;
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
- guid: string;
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
- guid: string;
128
+ id: number;
128
129
  parent: Container | null;
129
130
  options: ContainerOptions;
130
131
  bind<T>(serviceIdentifier: ServiceIdentifier<T>): BindingToSyntax<T>;
@@ -140,6 +141,7 @@ declare namespace interfaces {
140
141
  getAll<T>(serviceIdentifier: ServiceIdentifier<T>): T[];
141
142
  resolve<T>(constructorFunction: interfaces.Newable<T>): T;
142
143
  load(...modules: ContainerModule[]): void;
144
+ loadAsync(...modules: AsyncContainerModule[]): Promise<void>;
143
145
  unload(...modules: ContainerModule[]): void;
144
146
  applyCustomMetadataReader(metadataReader: MetadataReader): void;
145
147
  applyMiddleware(...middleware: Middleware[]): void;
@@ -152,10 +154,15 @@ declare namespace interfaces {
152
154
  type Unbind = <T>(serviceIdentifier: ServiceIdentifier<T>) => void;
153
155
  type IsBound = <T>(serviceIdentifier: ServiceIdentifier<T>) => boolean;
154
156
  interface ContainerModule {
155
- guid: string;
157
+ id: number;
156
158
  registry: ContainerModuleCallBack;
157
159
  }
160
+ interface AsyncContainerModule {
161
+ id: number;
162
+ registry: AsyncContainerModuleCallBack;
163
+ }
158
164
  type ContainerModuleCallBack = (bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => void;
165
+ type AsyncContainerModuleCallBack = (bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => Promise<void>;
159
166
  interface ContainerSnapshot {
160
167
  bindings: Lookup<Binding<any>>;
161
168
  middleware: Next | null;
@@ -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 { guid } from "./utils/guid";
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,6 +1,6 @@
1
1
  import { interfaces } from "../interfaces/interfaces";
2
2
  declare class Context implements interfaces.Context {
3
- guid: string;
3
+ id: number;
4
4
  container: interfaces.Container;
5
5
  plan: interfaces.Plan;
6
6
  currentRequest: interfaces.Request;
@@ -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
- export { getDependencies };
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
- guid: string;
3
+ id: number;
4
4
  serviceIdentifier: interfaces.ServiceIdentifier<any>;
5
5
  parentContext: interfaces.Context;
6
6
  parentRequest: interfaces.Request | null;
@@ -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
- guid: string;
4
+ id: number;
5
5
  type: interfaces.TargetType;
6
6
  serviceIdentifier: interfaces.ServiceIdentifier<any>;
7
7
  name: interfaces.QueryableString;
@@ -0,0 +1,2 @@
1
+ declare function id(): number;
2
+ export { id };
@@ -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
  }
@@ -1,8 +1,8 @@
1
1
  import { BindingTypeEnum } from "../constants/literal_types";
2
- import { guid } from "../utils/guid";
2
+ import { id } from "../utils/id";
3
3
  var Binding = (function () {
4
4
  function Binding(serviceIdentifier, scope) {
5
- this.guid = guid();
5
+ this.id = id();
6
6
  this.activated = false;
7
7
  this.serviceIdentifier = serviceIdentifier;
8
8
  this.scope = scope;
@@ -22,14 +22,22 @@ export var INVALID_TO_SELF_VALUE = "The toSelf function can only be applied when
22
22
  "used as service identifier";
23
23
  export var INVALID_DECORATOR_OPERATION = "The @inject @multiInject @tagged and @named decorators " +
24
24
  "must be applied to the parameters of a class constructor or a class property.";
25
- export var ARGUMENTS_LENGTH_MISMATCH_1 = "The number of constructor arguments in the derived class ";
26
- export var ARGUMENTS_LENGTH_MISMATCH_2 = " must be >= than the number of constructor arguments of its base class.";
25
+ export var ARGUMENTS_LENGTH_MISMATCH = function () {
26
+ var values = [];
27
+ for (var _i = 0; _i < arguments.length; _i++) {
28
+ values[_i] = arguments[_i];
29
+ }
30
+ return "The number of constructor arguments in the derived class " +
31
+ (values[0] + " must be >= than the number of constructor arguments of its base class.");
32
+ };
27
33
  export var CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = "Invalid Container constructor argument. Container options " +
28
34
  "must be an object.";
29
35
  export var CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = "Invalid Container option. Default scope must " +
30
36
  "be a string ('singleton' or 'transient').";
31
37
  export var CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = "Invalid Container option. Auto bind injectable must " +
32
38
  "be a boolean";
39
+ export var CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = "Invalid Container option. Skip base check must " +
40
+ "be a boolean";
33
41
  export var MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
34
42
  export var POST_CONSTRUCT_ERROR = function () {
35
43
  var values = [];
@@ -1,3 +1,38 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ return new (P || (P = Promise))(function (resolve, reject) {
3
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
4
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
5
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
6
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
7
+ });
8
+ };
9
+ var __generator = (this && this.__generator) || function (thisArg, body) {
10
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
11
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ function verb(n) { return function (v) { return step([n, v]); }; }
13
+ function step(op) {
14
+ if (f) throw new TypeError("Generator is already executing.");
15
+ while (_) try {
16
+ if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
17
+ if (y = 0, t) op = [0, t.value];
18
+ switch (op[0]) {
19
+ case 0: case 1: t = op; break;
20
+ case 4: _.label++; return { value: op[1], done: false };
21
+ case 5: _.label++; y = op[1]; op = [0]; continue;
22
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
23
+ default:
24
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
25
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
26
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
27
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
28
+ if (t[2]) _.ops.pop();
29
+ _.trys.pop(); continue;
30
+ }
31
+ op = body.call(thisArg, _);
32
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
33
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
34
+ }
35
+ };
1
36
  import { Binding } from "../bindings/binding";
2
37
  import * as ERROR_MSGS from "../constants/error_msgs";
3
38
  import { BindingScopeEnum, TargetTypeEnum } from "../constants/literal_types";
@@ -6,40 +41,42 @@ import { MetadataReader } from "../planning/metadata_reader";
6
41
  import { createMockRequest, getBindingDictionary, plan } from "../planning/planner";
7
42
  import { resolve } from "../resolution/resolver";
8
43
  import { BindingToSyntax } from "../syntax/binding_to_syntax";
9
- import { guid } from "../utils/guid";
44
+ import { id } from "../utils/id";
10
45
  import { getServiceIdentifierAsString } from "../utils/serialization";
11
46
  import { ContainerSnapshot } from "./container_snapshot";
12
47
  import { Lookup } from "./lookup";
13
48
  var Container = (function () {
14
49
  function Container(containerOptions) {
15
- if (containerOptions !== undefined) {
16
- if (typeof containerOptions !== "object") {
17
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
18
- }
19
- else {
20
- if (containerOptions.defaultScope !== undefined &&
21
- containerOptions.defaultScope !== BindingScopeEnum.Singleton &&
22
- containerOptions.defaultScope !== BindingScopeEnum.Transient &&
23
- containerOptions.defaultScope !== BindingScopeEnum.Request) {
24
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
25
- }
26
- if (containerOptions.autoBindInjectable !== undefined &&
27
- typeof containerOptions.autoBindInjectable !== "boolean") {
28
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
29
- }
30
- }
31
- this.options = {
32
- autoBindInjectable: containerOptions.autoBindInjectable,
33
- defaultScope: containerOptions.defaultScope
34
- };
50
+ var options = containerOptions || {};
51
+ if (typeof options !== "object") {
52
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
35
53
  }
36
- else {
37
- this.options = {
38
- autoBindInjectable: false,
39
- defaultScope: BindingScopeEnum.Transient
40
- };
54
+ if (options.defaultScope === undefined) {
55
+ options.defaultScope = BindingScopeEnum.Transient;
56
+ }
57
+ else if (options.defaultScope !== BindingScopeEnum.Singleton &&
58
+ options.defaultScope !== BindingScopeEnum.Transient &&
59
+ options.defaultScope !== BindingScopeEnum.Request) {
60
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
61
+ }
62
+ if (options.autoBindInjectable === undefined) {
63
+ options.autoBindInjectable = false;
41
64
  }
42
- this.guid = guid();
65
+ else if (typeof options.autoBindInjectable !== "boolean") {
66
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
67
+ }
68
+ if (options.skipBaseClassChecks === undefined) {
69
+ options.skipBaseClassChecks = false;
70
+ }
71
+ else if (typeof options.skipBaseClassChecks !== "boolean") {
72
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK);
73
+ }
74
+ this.options = {
75
+ autoBindInjectable: options.autoBindInjectable,
76
+ defaultScope: options.defaultScope,
77
+ skipBaseClassChecks: options.skipBaseClassChecks
78
+ };
79
+ this.id = id();
43
80
  this._bindingDictionary = new Lookup();
44
81
  this._snapshots = [];
45
82
  this._middleware = null;
@@ -63,46 +100,44 @@ var Container = (function () {
63
100
  return container;
64
101
  };
65
102
  Container.prototype.load = function () {
66
- var _this = this;
67
103
  var modules = [];
68
104
  for (var _i = 0; _i < arguments.length; _i++) {
69
105
  modules[_i] = arguments[_i];
70
106
  }
71
- var setModuleId = function (bindingToSyntax, moduleId) {
72
- bindingToSyntax._binding.moduleId = moduleId;
73
- };
74
- var getBindFunction = function (moduleId) {
75
- return function (serviceIdentifier) {
76
- var bindingToSyntax = _this.bind.call(_this, serviceIdentifier);
77
- setModuleId(bindingToSyntax, moduleId);
78
- return bindingToSyntax;
79
- };
80
- };
81
- var getUnbindFunction = function (moduleId) {
82
- return function (serviceIdentifier) {
83
- var _unbind = _this.unbind.bind(_this);
84
- _unbind(serviceIdentifier);
85
- };
86
- };
87
- var getIsboundFunction = function (moduleId) {
88
- return function (serviceIdentifier) {
89
- var _isBound = _this.isBound.bind(_this);
90
- return _isBound(serviceIdentifier);
91
- };
92
- };
93
- var getRebindFunction = function (moduleId) {
94
- return function (serviceIdentifier) {
95
- var bindingToSyntax = _this.rebind.call(_this, serviceIdentifier);
96
- setModuleId(bindingToSyntax, moduleId);
97
- return bindingToSyntax;
98
- };
99
- };
100
- modules.forEach(function (module) {
101
- var bindFunction = getBindFunction(module.guid);
102
- var unbindFunction = getUnbindFunction(module.guid);
103
- var isboundFunction = getIsboundFunction(module.guid);
104
- var rebindFunction = getRebindFunction(module.guid);
105
- module.registry(bindFunction, unbindFunction, isboundFunction, rebindFunction);
107
+ var getHelpers = this._getContainerModuleHelpersFactory();
108
+ for (var _a = 0, modules_1 = modules; _a < modules_1.length; _a++) {
109
+ var currentModule = modules_1[_a];
110
+ var containerModuleHelpers = getHelpers(currentModule.id);
111
+ currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction);
112
+ }
113
+ };
114
+ Container.prototype.loadAsync = function () {
115
+ var modules = [];
116
+ for (var _i = 0; _i < arguments.length; _i++) {
117
+ modules[_i] = arguments[_i];
118
+ }
119
+ return __awaiter(this, void 0, void 0, function () {
120
+ var getHelpers, _a, modules_2, currentModule, containerModuleHelpers;
121
+ return __generator(this, function (_b) {
122
+ switch (_b.label) {
123
+ case 0:
124
+ getHelpers = this._getContainerModuleHelpersFactory();
125
+ _a = 0, modules_2 = modules;
126
+ _b.label = 1;
127
+ case 1:
128
+ if (!(_a < modules_2.length)) return [3, 4];
129
+ currentModule = modules_2[_a];
130
+ containerModuleHelpers = getHelpers(currentModule.id);
131
+ return [4, currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction)];
132
+ case 2:
133
+ _b.sent();
134
+ _b.label = 3;
135
+ case 3:
136
+ _a++;
137
+ return [3, 1];
138
+ case 4: return [2];
139
+ }
140
+ });
106
141
  });
107
142
  };
108
143
  Container.prototype.unload = function () {
@@ -115,7 +150,7 @@ var Container = (function () {
115
150
  return item.moduleId === expected;
116
151
  }; };
117
152
  modules.forEach(function (module) {
118
- var condition = conditionFactory(module.guid);
153
+ var condition = conditionFactory(module.id);
119
154
  _this._bindingDictionary.removeByCondition(condition);
120
155
  });
121
156
  };
@@ -173,8 +208,8 @@ var Container = (function () {
173
208
  this._bindingDictionary = snapshot.bindings;
174
209
  this._middleware = snapshot.middleware;
175
210
  };
176
- Container.prototype.createChild = function () {
177
- var child = new Container();
211
+ Container.prototype.createChild = function (containerOptions) {
212
+ var child = new Container(containerOptions || this.options);
178
213
  child.parent = this;
179
214
  return child;
180
215
  };
@@ -208,11 +243,50 @@ var Container = (function () {
208
243
  return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
209
244
  };
210
245
  Container.prototype.resolve = function (constructorFunction) {
211
- var tempContainer = new Container();
246
+ var tempContainer = this.createChild();
212
247
  tempContainer.bind(constructorFunction).toSelf();
213
- tempContainer.parent = this;
214
248
  return tempContainer.get(constructorFunction);
215
249
  };
250
+ Container.prototype._getContainerModuleHelpersFactory = function () {
251
+ var _this = this;
252
+ var setModuleId = function (bindingToSyntax, moduleId) {
253
+ bindingToSyntax._binding.moduleId = moduleId;
254
+ };
255
+ var getBindFunction = function (moduleId) {
256
+ return function (serviceIdentifier) {
257
+ var _bind = _this.bind.bind(_this);
258
+ var bindingToSyntax = _bind(serviceIdentifier);
259
+ setModuleId(bindingToSyntax, moduleId);
260
+ return bindingToSyntax;
261
+ };
262
+ };
263
+ var getUnbindFunction = function (moduleId) {
264
+ return function (serviceIdentifier) {
265
+ var _unbind = _this.unbind.bind(_this);
266
+ _unbind(serviceIdentifier);
267
+ };
268
+ };
269
+ var getIsboundFunction = function (moduleId) {
270
+ return function (serviceIdentifier) {
271
+ var _isBound = _this.isBound.bind(_this);
272
+ return _isBound(serviceIdentifier);
273
+ };
274
+ };
275
+ var getRebindFunction = function (moduleId) {
276
+ return function (serviceIdentifier) {
277
+ var _rebind = _this.rebind.bind(_this);
278
+ var bindingToSyntax = _rebind(serviceIdentifier);
279
+ setModuleId(bindingToSyntax, moduleId);
280
+ return bindingToSyntax;
281
+ };
282
+ };
283
+ return function (mId) { return ({
284
+ bindFunction: getBindFunction(mId),
285
+ isboundFunction: getIsboundFunction(mId),
286
+ rebindFunction: getRebindFunction(mId),
287
+ unbindFunction: getUnbindFunction(mId)
288
+ }); };
289
+ };
216
290
  Container.prototype._get = function (avoidConstraints, isMultiInject, targetType, serviceIdentifier, key, value) {
217
291
  var result = null;
218
292
  var defaultArgs = {
@@ -1,9 +1,17 @@
1
- import { guid } from "../utils/guid";
1
+ import { id } from "../utils/id";
2
2
  var ContainerModule = (function () {
3
3
  function ContainerModule(registry) {
4
- this.guid = guid();
4
+ this.id = id();
5
5
  this.registry = registry;
6
6
  }
7
7
  return ContainerModule;
8
8
  }());
9
9
  export { ContainerModule };
10
+ var AsyncContainerModule = (function () {
11
+ function AsyncContainerModule(registry) {
12
+ this.id = id();
13
+ this.registry = registry;
14
+ }
15
+ return AsyncContainerModule;
16
+ }());
17
+ export { AsyncContainerModule };
package/es/inversify.js CHANGED
@@ -2,7 +2,7 @@ import * as keys from "./constants/metadata_keys";
2
2
  export var METADATA_KEY = keys;
3
3
  export { Container } from "./container/container";
4
4
  export { BindingScopeEnum, BindingTypeEnum, TargetTypeEnum } from "./constants/literal_types";
5
- export { ContainerModule } from "./container/container_module";
5
+ export { AsyncContainerModule, ContainerModule } from "./container/container_module";
6
6
  export { injectable } from "./annotation/injectable";
7
7
  export { tagged } from "./annotation/tagged";
8
8
  export { named } from "./annotation/named";
@@ -13,7 +13,7 @@ export { multiInject } from "./annotation/multi_inject";
13
13
  export { targetName } from "./annotation/target_name";
14
14
  export { postConstruct } from "./annotation/post_construct";
15
15
  export { MetadataReader } from "./planning/metadata_reader";
16
- export { guid } from "./utils/guid";
16
+ export { id } from "./utils/id";
17
17
  export { decorate } from "./annotation/decorator_utils";
18
18
  export { traverseAncerstors, taggedConstraint, namedConstraint, typeConstraint } from "./syntax/constraint_helpers";
19
19
  export { getServiceIdentifierAsString } from "./utils/serialization";
@@ -1,7 +1,7 @@
1
- import { guid } from "../utils/guid";
1
+ import { id } from "../utils/id";
2
2
  var Context = (function () {
3
3
  function Context(container) {
4
- this.guid = guid();
4
+ this.id = id();
5
5
  this.container = container;
6
6
  }
7
7
  Context.prototype.addPlan = function (plan) {
@@ -7,7 +7,7 @@ import { circularDependencyToException, getServiceIdentifierAsString, listMetada
7
7
  import { Context } from "./context";
8
8
  import { Metadata } from "./metadata";
9
9
  import { Plan } from "./plan";
10
- import { getDependencies } from "./reflection_utils";
10
+ import { getBaseClassDependencyCount, getDependencies, getFunctionName } from "./reflection_utils";
11
11
  import { Request } from "./request";
12
12
  import { Target } from "./target";
13
13
  function getBindingDictionary(cntnr) {
@@ -101,6 +101,13 @@ function _createSubRequests(metadataReader, avoidConstraints, serviceIdentifier,
101
101
  }
102
102
  if (binding.type === BindingTypeEnum.Instance && binding.implementationType !== null) {
103
103
  var dependencies = getDependencies(metadataReader, binding.implementationType);
104
+ if (!context.container.options.skipBaseClassChecks) {
105
+ var baseClassDependencyCount = getBaseClassDependencyCount(metadataReader, binding.implementationType);
106
+ if (dependencies.length < baseClassDependencyCount) {
107
+ var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH(getFunctionName(binding.implementationType));
108
+ throw new Error(error);
109
+ }
110
+ }
104
111
  dependencies.forEach(function (dependency) {
105
112
  _createSubRequests(metadataReader, false, dependency.serviceIdentifier, context, subChildRequest, dependency);
106
113
  });
@@ -23,12 +23,6 @@ function getTargets(metadataReader, constructorName, func, isBaseClass) {
23
23
  var constructorTargets = getConstructorArgsAsTargets(isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata, iterations);
24
24
  var propertyTargets = getClassPropsAsTargets(metadataReader, func);
25
25
  var targets = constructorTargets.concat(propertyTargets);
26
- var baseClassDependencyCount = getBaseClassDependencyCount(metadataReader, func);
27
- if (targets.length < baseClassDependencyCount) {
28
- var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_1 +
29
- constructorName + ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_2;
30
- throw new Error(error);
31
- }
32
26
  return targets;
33
27
  }
34
28
  function getConstructorArgsAsTarget(index, isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata) {
@@ -123,4 +117,4 @@ function formatTargetMetadata(targetMetadata) {
123
117
  unmanaged: targetMetadataMap[METADATA_KEY.UNMANAGED_TAG]
124
118
  };
125
119
  }
126
- export { getDependencies };
120
+ export { getDependencies, getBaseClassDependencyCount, getFunctionName };
@@ -1,7 +1,7 @@
1
- import { guid } from "../utils/guid";
1
+ import { id } from "../utils/id";
2
2
  var Request = (function () {
3
3
  function Request(serviceIdentifier, parentContext, parentRequest, bindings, target) {
4
- this.guid = guid();
4
+ this.id = id();
5
5
  this.serviceIdentifier = serviceIdentifier;
6
6
  this.parentContext = parentContext;
7
7
  this.parentRequest = parentRequest;
@@ -1,10 +1,10 @@
1
1
  import * as METADATA_KEY from "../constants/metadata_keys";
2
- import { guid } from "../utils/guid";
2
+ import { id } from "../utils/id";
3
3
  import { Metadata } from "./metadata";
4
4
  import { QueryableString } from "./queryable_string";
5
5
  var Target = (function () {
6
6
  function Target(type, name, serviceIdentifier, namedOrTagged) {
7
- this.guid = guid();
7
+ this.id = id();
8
8
  this.type = type;
9
9
  this.serviceIdentifier = serviceIdentifier;
10
10
  this.name = new QueryableString(name || "");
@@ -45,8 +45,8 @@ var _resolveRequest = function (requestScope) {
45
45
  }
46
46
  if (isRequestSingleton &&
47
47
  requestScope !== null &&
48
- requestScope.has(binding_1.guid)) {
49
- return requestScope.get(binding_1.guid);
48
+ requestScope.has(binding_1.id)) {
49
+ return requestScope.get(binding_1.id);
50
50
  }
51
51
  if (binding_1.type === BindingTypeEnum.ConstantValue) {
52
52
  result = binding_1.cache;
@@ -82,8 +82,8 @@ var _resolveRequest = function (requestScope) {
82
82
  }
83
83
  if (isRequestSingleton &&
84
84
  requestScope !== null &&
85
- !requestScope.has(binding_1.guid)) {
86
- requestScope.set(binding_1.guid, result);
85
+ !requestScope.has(binding_1.id)) {
86
+ requestScope.set(binding_1.id, result);
87
87
  }
88
88
  return result;
89
89
  }
package/es/utils/id.js ADDED
@@ -0,0 +1,5 @@
1
+ var idCounter = 0;
2
+ function id() {
3
+ return idCounter++;
4
+ }
5
+ export { id };
@@ -30,7 +30,7 @@ function _tagParameterOrProperty(metadataKey, annotationTarget, propertyName, me
30
30
  for (var _i = 0, paramOrPropertyMetadata_1 = paramOrPropertyMetadata; _i < paramOrPropertyMetadata_1.length; _i++) {
31
31
  var m = paramOrPropertyMetadata_1[_i];
32
32
  if (m.key === metadata.key) {
33
- throw new Error(ERROR_MSGS.DUPLICATED_METADATA + " " + m.key);
33
+ throw new Error(ERROR_MSGS.DUPLICATED_METADATA + " " + m.key.toString());
34
34
  }
35
35
  }
36
36
  }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var literal_types_1 = require("../constants/literal_types");
4
- var guid_1 = require("../utils/guid");
4
+ var id_1 = require("../utils/id");
5
5
  var Binding = (function () {
6
6
  function Binding(serviceIdentifier, scope) {
7
- this.guid = guid_1.guid();
7
+ this.id = id_1.id();
8
8
  this.activated = false;
9
9
  this.serviceIdentifier = serviceIdentifier;
10
10
  this.scope = scope;