inversify 4.11.1 → 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.
@@ -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 = [];
@@ -38,33 +38,35 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  var Container = (function () {
40
40
  function Container(containerOptions) {
41
- if (containerOptions !== undefined) {
42
- if (typeof containerOptions !== "object") {
43
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
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
- else {
63
- this.options = {
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
  }
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
+ };
68
70
  this.guid = guid_1.guid();
69
71
  this._bindingDictionary = new lookup_1.Lookup();
70
72
  this._snapshots = [];
@@ -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);
202
204
  child.parent = this;
203
205
  return child;
204
206
  };
@@ -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/appveyor.yml CHANGED
@@ -1,34 +1,34 @@
1
- # AppVeyor file
2
- # http://www.appveyor.com/docs/appveyor-yml
3
-
4
- # Build version format
5
- version: "{build}"
6
-
7
- # Test against this version of Node.js
8
- environment:
9
- NODE_ENV: test
10
-
11
- matrix:
12
- - nodejs_version: "9.3.0"
13
-
14
- build: off
15
-
16
- branches:
17
- only:
18
- - master
19
-
20
- install:
21
- - ps: Install-Product node $env:nodejs_version
22
- - npm install -g npm
23
- - npm config set progress=false
24
- - npm install
25
-
26
- # Fix line endings on Windows
27
- init:
28
- - git config --global core.autocrlf true
29
-
30
- test_script:
31
- # Output useful info for debugging.
32
- - node --version && npm --version
33
- - ps: "npm --version # PowerShell" # Pass comment to PS for easier debugging
34
- - cmd: npm run test
1
+ # AppVeyor file
2
+ # http://www.appveyor.com/docs/appveyor-yml
3
+
4
+ # Build version format
5
+ version: "{build}"
6
+
7
+ # Test against this version of Node.js
8
+ environment:
9
+ NODE_ENV: test
10
+
11
+ matrix:
12
+ - nodejs_version: "9.3.0"
13
+
14
+ build: off
15
+
16
+ branches:
17
+ only:
18
+ - master
19
+
20
+ install:
21
+ - ps: Install-Product node $env:nodejs_version
22
+ - npm install -g npm
23
+ - npm config set progress=false
24
+ - npm install
25
+
26
+ # Fix line endings on Windows
27
+ init:
28
+ - git config --global core.autocrlf true
29
+
30
+ test_script:
31
+ # Output useful info for debugging.
32
+ - node --version && npm --version
33
+ - ps: "npm --version # PowerShell" # Pass comment to PS for easier debugging
34
+ - cmd: npm run test
@@ -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;
@@ -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;
@@ -122,6 +122,7 @@ 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
  guid: string;
@@ -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 };
@@ -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 = [];
@@ -47,33 +47,35 @@ import { ContainerSnapshot } from "./container_snapshot";
47
47
  import { Lookup } from "./lookup";
48
48
  var Container = (function () {
49
49
  function Container(containerOptions) {
50
- if (containerOptions !== undefined) {
51
- if (typeof containerOptions !== "object") {
52
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
53
- }
54
- else {
55
- if (containerOptions.defaultScope !== undefined &&
56
- containerOptions.defaultScope !== BindingScopeEnum.Singleton &&
57
- containerOptions.defaultScope !== BindingScopeEnum.Transient &&
58
- containerOptions.defaultScope !== BindingScopeEnum.Request) {
59
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
60
- }
61
- if (containerOptions.autoBindInjectable !== undefined &&
62
- typeof containerOptions.autoBindInjectable !== "boolean") {
63
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
64
- }
65
- }
66
- this.options = {
67
- autoBindInjectable: containerOptions.autoBindInjectable,
68
- defaultScope: containerOptions.defaultScope
69
- };
50
+ var options = containerOptions || {};
51
+ if (typeof options !== "object") {
52
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
70
53
  }
71
- else {
72
- this.options = {
73
- autoBindInjectable: false,
74
- defaultScope: BindingScopeEnum.Transient
75
- };
54
+ if (options.defaultScope === undefined) {
55
+ options.defaultScope = BindingScopeEnum.Transient;
76
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;
64
+ }
65
+ else if (typeof options.autoBindInjectable !== "boolean") {
66
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
67
+ }
68
+ if (options.skipBaseClassChecks === undefined) {
69
+ options.skipBaseClassChecks = false;
70
+ }
71
+ else if (typeof options.skipBaseClassChecks !== "boolean") {
72
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK);
73
+ }
74
+ this.options = {
75
+ autoBindInjectable: options.autoBindInjectable,
76
+ defaultScope: options.defaultScope,
77
+ skipBaseClassChecks: options.skipBaseClassChecks
78
+ };
77
79
  this.guid = guid();
78
80
  this._bindingDictionary = new Lookup();
79
81
  this._snapshots = [];
@@ -206,8 +208,8 @@ var Container = (function () {
206
208
  this._bindingDictionary = snapshot.bindings;
207
209
  this._middleware = snapshot.middleware;
208
210
  };
209
- Container.prototype.createChild = function () {
210
- var child = new Container();
211
+ Container.prototype.createChild = function (containerOptions) {
212
+ var child = new Container(containerOptions);
211
213
  child.parent = this;
212
214
  return child;
213
215
  };
@@ -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 };
@@ -24,14 +24,22 @@ exports.INVALID_TO_SELF_VALUE = "The toSelf function can only be applied when a
24
24
  "used as service identifier";
25
25
  exports.INVALID_DECORATOR_OPERATION = "The @inject @multiInject @tagged and @named decorators " +
26
26
  "must be applied to the parameters of a class constructor or a class property.";
27
- exports.ARGUMENTS_LENGTH_MISMATCH_1 = "The number of constructor arguments in the derived class ";
28
- exports.ARGUMENTS_LENGTH_MISMATCH_2 = " must be >= than the number of constructor arguments of its base class.";
27
+ exports.ARGUMENTS_LENGTH_MISMATCH = function () {
28
+ var values = [];
29
+ for (var _i = 0; _i < arguments.length; _i++) {
30
+ values[_i] = arguments[_i];
31
+ }
32
+ return "The number of constructor arguments in the derived class " +
33
+ (values[0] + " must be >= than the number of constructor arguments of its base class.");
34
+ };
29
35
  exports.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = "Invalid Container constructor argument. Container options " +
30
36
  "must be an object.";
31
37
  exports.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = "Invalid Container option. Default scope must " +
32
38
  "be a string ('singleton' or 'transient').";
33
39
  exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = "Invalid Container option. Auto bind injectable must " +
34
40
  "be a boolean";
41
+ exports.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = "Invalid Container option. Skip base check must " +
42
+ "be a boolean";
35
43
  exports.MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
36
44
  exports.POST_CONSTRUCT_ERROR = function () {
37
45
  var values = [];
@@ -49,33 +49,35 @@ var container_snapshot_1 = require("./container_snapshot");
49
49
  var lookup_1 = require("./lookup");
50
50
  var Container = (function () {
51
51
  function Container(containerOptions) {
52
- if (containerOptions !== undefined) {
53
- if (typeof containerOptions !== "object") {
54
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
55
- }
56
- else {
57
- if (containerOptions.defaultScope !== undefined &&
58
- containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
59
- containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
60
- containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
61
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
62
- }
63
- if (containerOptions.autoBindInjectable !== undefined &&
64
- typeof containerOptions.autoBindInjectable !== "boolean") {
65
- throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
66
- }
67
- }
68
- this.options = {
69
- autoBindInjectable: containerOptions.autoBindInjectable,
70
- defaultScope: containerOptions.defaultScope
71
- };
52
+ var options = containerOptions || {};
53
+ if (typeof options !== "object") {
54
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
72
55
  }
73
- else {
74
- this.options = {
75
- autoBindInjectable: false,
76
- defaultScope: literal_types_1.BindingScopeEnum.Transient
77
- };
56
+ if (options.defaultScope === undefined) {
57
+ options.defaultScope = literal_types_1.BindingScopeEnum.Transient;
78
58
  }
59
+ else if (options.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
60
+ options.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
61
+ options.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
62
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
63
+ }
64
+ if (options.autoBindInjectable === undefined) {
65
+ options.autoBindInjectable = false;
66
+ }
67
+ else if (typeof options.autoBindInjectable !== "boolean") {
68
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
69
+ }
70
+ if (options.skipBaseClassChecks === undefined) {
71
+ options.skipBaseClassChecks = false;
72
+ }
73
+ else if (typeof options.skipBaseClassChecks !== "boolean") {
74
+ throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK);
75
+ }
76
+ this.options = {
77
+ autoBindInjectable: options.autoBindInjectable,
78
+ defaultScope: options.defaultScope,
79
+ skipBaseClassChecks: options.skipBaseClassChecks
80
+ };
79
81
  this.guid = guid_1.guid();
80
82
  this._bindingDictionary = new lookup_1.Lookup();
81
83
  this._snapshots = [];
@@ -208,8 +210,8 @@ var Container = (function () {
208
210
  this._bindingDictionary = snapshot.bindings;
209
211
  this._middleware = snapshot.middleware;
210
212
  };
211
- Container.prototype.createChild = function () {
212
- var child = new Container();
213
+ Container.prototype.createChild = function (containerOptions) {
214
+ var child = new Container(containerOptions);
213
215
  child.parent = this;
214
216
  return child;
215
217
  };
@@ -104,6 +104,13 @@ function _createSubRequests(metadataReader, avoidConstraints, serviceIdentifier,
104
104
  }
105
105
  if (binding.type === literal_types_1.BindingTypeEnum.Instance && binding.implementationType !== null) {
106
106
  var dependencies = reflection_utils_1.getDependencies(metadataReader, binding.implementationType);
107
+ if (!context.container.options.skipBaseClassChecks) {
108
+ var baseClassDependencyCount = reflection_utils_1.getBaseClassDependencyCount(metadataReader, binding.implementationType);
109
+ if (dependencies.length < baseClassDependencyCount) {
110
+ var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH(reflection_utils_1.getFunctionName(binding.implementationType));
111
+ throw new Error(error);
112
+ }
113
+ }
107
114
  dependencies.forEach(function (dependency) {
108
115
  _createSubRequests(metadataReader, false, dependency.serviceIdentifier, context, subChildRequest, dependency);
109
116
  });
@@ -5,6 +5,7 @@ var ERROR_MSGS = require("../constants/error_msgs");
5
5
  var literal_types_1 = require("../constants/literal_types");
6
6
  var METADATA_KEY = require("../constants/metadata_keys");
7
7
  var serialization_1 = require("../utils/serialization");
8
+ exports.getFunctionName = serialization_1.getFunctionName;
8
9
  var target_1 = require("./target");
9
10
  function getDependencies(metadataReader, func) {
10
11
  var constructorName = serialization_1.getFunctionName(func);
@@ -26,12 +27,6 @@ function getTargets(metadataReader, constructorName, func, isBaseClass) {
26
27
  var constructorTargets = getConstructorArgsAsTargets(isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata, iterations);
27
28
  var propertyTargets = getClassPropsAsTargets(metadataReader, func);
28
29
  var targets = constructorTargets.concat(propertyTargets);
29
- var baseClassDependencyCount = getBaseClassDependencyCount(metadataReader, func);
30
- if (targets.length < baseClassDependencyCount) {
31
- var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_1 +
32
- constructorName + ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_2;
33
- throw new Error(error);
34
- }
35
30
  return targets;
36
31
  }
37
32
  function getConstructorArgsAsTarget(index, isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata) {
@@ -114,6 +109,7 @@ function getBaseClassDependencyCount(metadataReader, func) {
114
109
  return 0;
115
110
  }
116
111
  }
112
+ exports.getBaseClassDependencyCount = getBaseClassDependencyCount;
117
113
  function formatTargetMetadata(targetMetadata) {
118
114
  var targetMetadataMap = {};
119
115
  targetMetadata.forEach(function (m) {