inversify 6.1.4 → 6.1.5-beta.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 (267) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/README.md +6 -15
  3. package/es/container/container.d.ts +2 -0
  4. package/es/container/module_activation_store.d.ts +2 -2
  5. package/es/interfaces/interfaces.d.ts +2 -2
  6. package/es/inversify.d.ts +1 -0
  7. package/es/inversify.js +3 -2
  8. package/es/inversify.js.LICENSE.txt +14 -0
  9. package/lib/annotation/decorator_utils.js +31 -25
  10. package/lib/annotation/inject.js +20 -10
  11. package/lib/annotation/inject_base.js +6 -6
  12. package/lib/annotation/injectable.js +20 -10
  13. package/lib/annotation/multi_inject.js +20 -10
  14. package/lib/annotation/named.js +20 -10
  15. package/lib/annotation/optional.js +20 -10
  16. package/lib/annotation/post_construct.js +21 -11
  17. package/lib/annotation/pre_destroy.js +21 -11
  18. package/lib/annotation/property_event_decorator.js +4 -4
  19. package/lib/annotation/tagged.js +2 -2
  20. package/lib/annotation/target_name.js +21 -11
  21. package/lib/annotation/unmanaged.js +21 -11
  22. package/lib/bindings/binding.js +23 -10
  23. package/lib/constants/error_msgs.js +15 -29
  24. package/lib/constants/literal_types.js +3 -3
  25. package/lib/container/container.d.ts +2 -0
  26. package/lib/container/container.js +317 -566
  27. package/lib/container/container_module.js +11 -9
  28. package/lib/container/container_snapshot.js +10 -8
  29. package/lib/container/lookup.js +61 -56
  30. package/lib/container/module_activation_store.d.ts +2 -2
  31. package/lib/container/module_activation_store.js +21 -24
  32. package/lib/interfaces/interfaces.d.ts +2 -2
  33. package/lib/inversify.d.ts +1 -0
  34. package/lib/inversify.js +19 -8
  35. package/lib/planning/context.js +12 -9
  36. package/lib/planning/metadata.js +27 -16
  37. package/lib/planning/metadata_reader.js +29 -24
  38. package/lib/planning/plan.js +5 -4
  39. package/lib/planning/planner.js +62 -53
  40. package/lib/planning/queryable_string.js +16 -16
  41. package/lib/planning/reflection_utils.js +25 -17
  42. package/lib/planning/request.js +15 -8
  43. package/lib/resolution/instantiation.js +59 -119
  44. package/lib/resolution/resolver.js +89 -134
  45. package/lib/scope/scope.js +17 -62
  46. package/lib/syntax/binding_in_syntax.js +12 -12
  47. package/lib/syntax/binding_in_when_on_syntax.js +50 -47
  48. package/lib/syntax/binding_on_syntax.js +9 -9
  49. package/lib/syntax/binding_to_syntax.js +70 -49
  50. package/lib/syntax/binding_when_on_syntax.js +42 -40
  51. package/lib/syntax/binding_when_syntax.js +54 -76
  52. package/lib/syntax/constraint_helpers.js +31 -23
  53. package/lib/utils/async.js +1 -1
  54. package/lib/utils/binding_utils.js +31 -29
  55. package/lib/utils/exceptions.js +19 -9
  56. package/lib/utils/id.js +1 -1
  57. package/lib/utils/js.js +2 -3
  58. package/lib/utils/serialization.js +42 -33
  59. package/package.json +14 -15
  60. package/amd/annotation/decorator_utils.d.ts +0 -16
  61. package/amd/annotation/decorator_utils.js +0 -119
  62. package/amd/annotation/inject.d.ts +0 -5
  63. package/amd/annotation/inject.js +0 -31
  64. package/amd/annotation/inject_base.d.ts +0 -4
  65. package/amd/annotation/inject_base.js +0 -16
  66. package/amd/annotation/injectable.d.ts +0 -2
  67. package/amd/annotation/injectable.js +0 -40
  68. package/amd/annotation/lazy_service_identifier.js +0 -4
  69. package/amd/annotation/multi_inject.d.ts +0 -5
  70. package/amd/annotation/multi_inject.js +0 -31
  71. package/amd/annotation/named.d.ts +0 -2
  72. package/amd/annotation/named.js +0 -32
  73. package/amd/annotation/optional.d.ts +0 -2
  74. package/amd/annotation/optional.js +0 -32
  75. package/amd/annotation/post_construct.d.ts +0 -4
  76. package/amd/annotation/post_construct.js +0 -32
  77. package/amd/annotation/pre_destroy.d.ts +0 -4
  78. package/amd/annotation/pre_destroy.js +0 -32
  79. package/amd/annotation/property_event_decorator.d.ts +0 -4
  80. package/amd/annotation/property_event_decorator.js +0 -16
  81. package/amd/annotation/tagged.d.ts +0 -2
  82. package/amd/annotation/tagged.js +0 -8
  83. package/amd/annotation/target_name.d.ts +0 -3
  84. package/amd/annotation/target_name.js +0 -35
  85. package/amd/annotation/unmanaged.d.ts +0 -3
  86. package/amd/annotation/unmanaged.js +0 -35
  87. package/amd/bindings/binding.d.ts +0 -20
  88. package/amd/bindings/binding.js +0 -40
  89. package/amd/bindings/binding_count.d.ts +0 -5
  90. package/amd/bindings/binding_count.js +0 -11
  91. package/amd/constants/error_msgs.d.ts +0 -30
  92. package/amd/constants/error_msgs.js +0 -75
  93. package/amd/constants/literal_types.d.ts +0 -5
  94. package/amd/constants/literal_types.js +0 -28
  95. package/amd/constants/metadata_keys.d.ts +0 -13
  96. package/amd/constants/metadata_keys.js +0 -28
  97. package/amd/container/container.d.ts +0 -73
  98. package/amd/container/container.js +0 -766
  99. package/amd/container/container_module.d.ts +0 -11
  100. package/amd/container/container_module.js +0 -21
  101. package/amd/container/container_snapshot.d.ts +0 -10
  102. package/amd/container/container_snapshot.js +0 -20
  103. package/amd/container/lookup.d.ts +0 -17
  104. package/amd/container/lookup.js +0 -132
  105. package/amd/container/module_activation_store.d.ts +0 -10
  106. package/amd/container/module_activation_store.js +0 -51
  107. package/amd/interfaces/interfaces.d.ts +0 -269
  108. package/amd/interfaces/interfaces.js +0 -4
  109. package/amd/inversify.d.ts +0 -24
  110. package/amd/inversify.js +0 -57
  111. package/amd/planning/context.d.ts +0 -11
  112. package/amd/planning/context.js +0 -19
  113. package/amd/planning/metadata.d.ts +0 -8
  114. package/amd/planning/metadata.js +0 -45
  115. package/amd/planning/metadata_reader.d.ts +0 -6
  116. package/amd/planning/metadata_reader.js +0 -49
  117. package/amd/planning/plan.d.ts +0 -7
  118. package/amd/planning/plan.js +0 -13
  119. package/amd/planning/planner.d.ts +0 -5
  120. package/amd/planning/planner.js +0 -187
  121. package/amd/planning/queryable_string.d.ts +0 -10
  122. package/amd/planning/queryable_string.js +0 -33
  123. package/amd/planning/reflection_utils.d.ts +0 -5
  124. package/amd/planning/reflection_utils.js +0 -55
  125. package/amd/planning/request.d.ts +0 -14
  126. package/amd/planning/request.js +0 -24
  127. package/amd/planning/target.js +0 -111
  128. package/amd/resolution/instantiation.d.ts +0 -3
  129. package/amd/resolution/instantiation.js +0 -219
  130. package/amd/resolution/resolver.d.ts +0 -3
  131. package/amd/resolution/resolver.js +0 -234
  132. package/amd/scope/scope.d.ts +0 -3
  133. package/amd/scope/scope.js +0 -93
  134. package/amd/syntax/binding_in_syntax.d.ts +0 -9
  135. package/amd/syntax/binding_in_syntax.js +0 -24
  136. package/amd/syntax/binding_in_when_on_syntax.d.ts +0 -29
  137. package/amd/syntax/binding_in_when_on_syntax.js +0 -75
  138. package/amd/syntax/binding_on_syntax.d.ts +0 -8
  139. package/amd/syntax/binding_on_syntax.js +0 -20
  140. package/amd/syntax/binding_to_syntax.d.ts +0 -18
  141. package/amd/syntax/binding_to_syntax.js +0 -116
  142. package/amd/syntax/binding_when_on_syntax.d.ts +0 -25
  143. package/amd/syntax/binding_when_on_syntax.js +0 -65
  144. package/amd/syntax/binding_when_syntax.d.ts +0 -21
  145. package/amd/syntax/binding_when_syntax.js +0 -107
  146. package/amd/syntax/constraint_helpers.d.ts +0 -6
  147. package/amd/syntax/constraint_helpers.js +0 -66
  148. package/amd/utils/async.d.ts +0 -3
  149. package/amd/utils/async.js +0 -17
  150. package/amd/utils/binding_utils.d.ts +0 -4
  151. package/amd/utils/binding_utils.js +0 -86
  152. package/amd/utils/clonable.d.ts +0 -3
  153. package/amd/utils/clonable.js +0 -11
  154. package/amd/utils/exceptions.d.ts +0 -2
  155. package/amd/utils/exceptions.js +0 -46
  156. package/amd/utils/factory_type.d.ts +0 -5
  157. package/amd/utils/factory_type.js +0 -11
  158. package/amd/utils/id.d.ts +0 -2
  159. package/amd/utils/id.js +0 -9
  160. package/amd/utils/js.d.ts +0 -1
  161. package/amd/utils/js.js +0 -18
  162. package/amd/utils/serialization.d.ts +0 -10
  163. package/amd/utils/serialization.js +0 -135
  164. package/es6/annotation/decorator_utils.d.ts +0 -16
  165. package/es6/annotation/decorator_utils.js +0 -114
  166. package/es6/annotation/inject.d.ts +0 -5
  167. package/es6/annotation/inject.js +0 -30
  168. package/es6/annotation/inject_base.d.ts +0 -4
  169. package/es6/annotation/inject_base.js +0 -17
  170. package/es6/annotation/injectable.d.ts +0 -2
  171. package/es6/annotation/injectable.js +0 -38
  172. package/es6/annotation/lazy_service_identifier.js +0 -2
  173. package/es6/annotation/multi_inject.d.ts +0 -5
  174. package/es6/annotation/multi_inject.js +0 -30
  175. package/es6/annotation/named.d.ts +0 -2
  176. package/es6/annotation/named.js +0 -32
  177. package/es6/annotation/optional.d.ts +0 -2
  178. package/es6/annotation/optional.js +0 -32
  179. package/es6/annotation/post_construct.d.ts +0 -4
  180. package/es6/annotation/post_construct.js +0 -31
  181. package/es6/annotation/pre_destroy.d.ts +0 -4
  182. package/es6/annotation/pre_destroy.js +0 -31
  183. package/es6/annotation/property_event_decorator.d.ts +0 -4
  184. package/es6/annotation/property_event_decorator.js +0 -15
  185. package/es6/annotation/tagged.d.ts +0 -2
  186. package/es6/annotation/tagged.js +0 -8
  187. package/es6/annotation/target_name.d.ts +0 -3
  188. package/es6/annotation/target_name.js +0 -35
  189. package/es6/annotation/unmanaged.d.ts +0 -3
  190. package/es6/annotation/unmanaged.js +0 -35
  191. package/es6/bindings/binding.d.ts +0 -20
  192. package/es6/bindings/binding.js +0 -39
  193. package/es6/bindings/binding_count.d.ts +0 -5
  194. package/es6/bindings/binding_count.js +0 -9
  195. package/es6/constants/error_msgs.d.ts +0 -30
  196. package/es6/constants/error_msgs.js +0 -59
  197. package/es6/constants/literal_types.d.ts +0 -5
  198. package/es6/constants/literal_types.js +0 -26
  199. package/es6/constants/metadata_keys.d.ts +0 -13
  200. package/es6/constants/metadata_keys.js +0 -26
  201. package/es6/container/container.d.ts +0 -73
  202. package/es6/container/container.js +0 -545
  203. package/es6/container/container_module.d.ts +0 -11
  204. package/es6/container/container_module.js +0 -18
  205. package/es6/container/container_snapshot.d.ts +0 -10
  206. package/es6/container/container_snapshot.js +0 -15
  207. package/es6/container/lookup.d.ts +0 -17
  208. package/es6/container/lookup.js +0 -125
  209. package/es6/container/module_activation_store.d.ts +0 -10
  210. package/es6/container/module_activation_store.js +0 -49
  211. package/es6/interfaces/interfaces.d.ts +0 -269
  212. package/es6/interfaces/interfaces.js +0 -2
  213. package/es6/inversify.d.ts +0 -24
  214. package/es6/inversify.js +0 -76
  215. package/es6/planning/context.d.ts +0 -11
  216. package/es6/planning/context.js +0 -17
  217. package/es6/planning/metadata.d.ts +0 -8
  218. package/es6/planning/metadata.js +0 -42
  219. package/es6/planning/metadata_reader.d.ts +0 -6
  220. package/es6/planning/metadata_reader.js +0 -44
  221. package/es6/planning/plan.d.ts +0 -7
  222. package/es6/planning/plan.js +0 -10
  223. package/es6/planning/planner.d.ts +0 -5
  224. package/es6/planning/planner.js +0 -194
  225. package/es6/planning/queryable_string.d.ts +0 -10
  226. package/es6/planning/queryable_string.js +0 -30
  227. package/es6/planning/reflection_utils.d.ts +0 -5
  228. package/es6/planning/reflection_utils.js +0 -53
  229. package/es6/planning/request.d.ts +0 -14
  230. package/es6/planning/request.js +0 -22
  231. package/es6/planning/target.js +0 -105
  232. package/es6/resolution/instantiation.d.ts +0 -3
  233. package/es6/resolution/instantiation.js +0 -158
  234. package/es6/resolution/resolver.d.ts +0 -3
  235. package/es6/resolution/resolver.js +0 -193
  236. package/es6/scope/scope.d.ts +0 -3
  237. package/es6/scope/scope.js +0 -57
  238. package/es6/syntax/binding_in_syntax.d.ts +0 -9
  239. package/es6/syntax/binding_in_syntax.js +0 -23
  240. package/es6/syntax/binding_in_when_on_syntax.d.ts +0 -29
  241. package/es6/syntax/binding_in_when_on_syntax.js +0 -75
  242. package/es6/syntax/binding_on_syntax.d.ts +0 -8
  243. package/es6/syntax/binding_on_syntax.js +0 -18
  244. package/es6/syntax/binding_to_syntax.d.ts +0 -18
  245. package/es6/syntax/binding_to_syntax.js +0 -110
  246. package/es6/syntax/binding_when_on_syntax.d.ts +0 -25
  247. package/es6/syntax/binding_when_on_syntax.js +0 -64
  248. package/es6/syntax/binding_when_syntax.d.ts +0 -21
  249. package/es6/syntax/binding_when_syntax.js +0 -84
  250. package/es6/syntax/constraint_helpers.d.ts +0 -6
  251. package/es6/syntax/constraint_helpers.js +0 -63
  252. package/es6/utils/async.d.ts +0 -3
  253. package/es6/utils/async.js +0 -15
  254. package/es6/utils/binding_utils.d.ts +0 -4
  255. package/es6/utils/binding_utils.js +0 -79
  256. package/es6/utils/clonable.d.ts +0 -3
  257. package/es6/utils/clonable.js +0 -9
  258. package/es6/utils/exceptions.d.ts +0 -2
  259. package/es6/utils/exceptions.js +0 -44
  260. package/es6/utils/factory_type.d.ts +0 -5
  261. package/es6/utils/factory_type.js +0 -9
  262. package/es6/utils/id.d.ts +0 -2
  263. package/es6/utils/id.js +0 -7
  264. package/es6/utils/js.d.ts +0 -1
  265. package/es6/utils/js.js +0 -15
  266. package/es6/utils/serialization.d.ts +0 -10
  267. package/es6/utils/serialization.js +0 -132
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
3
  if (k2 === undefined) k2 = k;
15
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -26,77 +15,52 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
26
15
  }) : function(o, v) {
27
16
  o["default"] = v;
28
17
  });
29
- var __importStar = (this && this.__importStar) || function (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
36
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
- return new (P || (P = Promise))(function (resolve, reject) {
39
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
- step((generator = generator.apply(thisArg, _arguments || [])).next());
43
- });
44
- };
45
- var __generator = (this && this.__generator) || function (thisArg, body) {
46
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
47
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
- function verb(n) { return function (v) { return step([n, v]); }; }
49
- function step(op) {
50
- if (f) throw new TypeError("Generator is already executing.");
51
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
- if (y = 0, t) op = [op[0] & 2, t.value];
54
- switch (op[0]) {
55
- case 0: case 1: t = op; break;
56
- case 4: _.label++; return { value: op[1], done: false };
57
- case 5: _.label++; y = op[1]; op = [0]; continue;
58
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
- default:
60
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
- if (t[2]) _.ops.pop();
65
- _.trys.pop(); continue;
66
- }
67
- op = body.call(thisArg, _);
68
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
- }
71
- };
72
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
73
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
74
- if (ar || !(i in from)) {
75
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
76
- ar[i] = from[i];
77
- }
78
- }
79
- return to.concat(ar || Array.prototype.slice.call(from));
80
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
81
35
  Object.defineProperty(exports, "__esModule", { value: true });
82
36
  exports.Container = void 0;
83
- var binding_1 = require("../bindings/binding");
84
- var ERROR_MSGS = __importStar(require("../constants/error_msgs"));
85
- var literal_types_1 = require("../constants/literal_types");
86
- var METADATA_KEY = __importStar(require("../constants/metadata_keys"));
87
- var metadata_reader_1 = require("../planning/metadata_reader");
88
- var planner_1 = require("../planning/planner");
89
- var resolver_1 = require("../resolution/resolver");
90
- var binding_to_syntax_1 = require("../syntax/binding_to_syntax");
91
- var async_1 = require("../utils/async");
92
- var id_1 = require("../utils/id");
93
- var serialization_1 = require("../utils/serialization");
94
- var container_snapshot_1 = require("./container_snapshot");
95
- var lookup_1 = require("./lookup");
96
- var module_activation_store_1 = require("./module_activation_store");
97
- var Container = (function () {
98
- function Container(containerOptions) {
99
- var options = containerOptions || {};
37
+ const binding_1 = require("../bindings/binding");
38
+ const ERROR_MSGS = __importStar(require("../constants/error_msgs"));
39
+ const literal_types_1 = require("../constants/literal_types");
40
+ const METADATA_KEY = __importStar(require("../constants/metadata_keys"));
41
+ const metadata_reader_1 = require("../planning/metadata_reader");
42
+ const planner_1 = require("../planning/planner");
43
+ const resolver_1 = require("../resolution/resolver");
44
+ const binding_to_syntax_1 = require("../syntax/binding_to_syntax");
45
+ const async_1 = require("../utils/async");
46
+ const id_1 = require("../utils/id");
47
+ const serialization_1 = require("../utils/serialization");
48
+ const container_snapshot_1 = require("./container_snapshot");
49
+ const lookup_1 = require("./lookup");
50
+ const module_activation_store_1 = require("./module_activation_store");
51
+ class Container {
52
+ id;
53
+ parent;
54
+ options;
55
+ _middleware;
56
+ _bindingDictionary;
57
+ _activations;
58
+ _deactivations;
59
+ _snapshots;
60
+ _metadataReader;
61
+ _moduleActivationStore;
62
+ constructor(containerOptions) {
63
+ const options = containerOptions || {};
100
64
  if (typeof options !== 'object') {
101
65
  throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
102
66
  }
@@ -135,224 +99,129 @@ var Container = (function () {
135
99
  this._metadataReader = new metadata_reader_1.MetadataReader();
136
100
  this._moduleActivationStore = new module_activation_store_1.ModuleActivationStore();
137
101
  }
138
- Container.merge = function (container1, container2) {
139
- var containers = [];
140
- for (var _i = 2; _i < arguments.length; _i++) {
141
- containers[_i - 2] = arguments[_i];
142
- }
143
- var container = new Container();
144
- var targetContainers = __spreadArray([
102
+ static merge(container1, container2, ...containers) {
103
+ const container = new Container();
104
+ const targetContainers = [
145
105
  container1,
146
- container2
147
- ], containers, true).map(function (targetContainer) {
148
- return (0, planner_1.getBindingDictionary)(targetContainer);
149
- });
150
- var bindingDictionary = (0, planner_1.getBindingDictionary)(container);
106
+ container2,
107
+ ...containers,
108
+ ].map((targetContainer) => (0, planner_1.getBindingDictionary)(targetContainer));
109
+ const bindingDictionary = (0, planner_1.getBindingDictionary)(container);
151
110
  function copyDictionary(origin, destination) {
152
- origin.traverse(function (_key, value) {
153
- value.forEach(function (binding) {
111
+ origin.traverse((_key, value) => {
112
+ value.forEach((binding) => {
154
113
  destination.add(binding.serviceIdentifier, binding.clone());
155
114
  });
156
115
  });
157
116
  }
158
- targetContainers.forEach(function (targetBindingDictionary) {
117
+ targetContainers.forEach((targetBindingDictionary) => {
159
118
  copyDictionary(targetBindingDictionary, bindingDictionary);
160
119
  });
161
120
  return container;
162
- };
163
- Container.prototype.load = function () {
164
- var modules = [];
165
- for (var _i = 0; _i < arguments.length; _i++) {
166
- modules[_i] = arguments[_i];
167
- }
168
- var getHelpers = this._getContainerModuleHelpersFactory();
169
- for (var _a = 0, modules_1 = modules; _a < modules_1.length; _a++) {
170
- var currentModule = modules_1[_a];
171
- var containerModuleHelpers = getHelpers(currentModule.id);
121
+ }
122
+ load(...modules) {
123
+ const getHelpers = this._getContainerModuleHelpersFactory();
124
+ for (const currentModule of modules) {
125
+ const containerModuleHelpers = getHelpers(currentModule.id);
172
126
  currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction, containerModuleHelpers.unbindAsyncFunction, containerModuleHelpers.onActivationFunction, containerModuleHelpers.onDeactivationFunction);
173
127
  }
174
- };
175
- Container.prototype.loadAsync = function () {
176
- var modules = [];
177
- for (var _i = 0; _i < arguments.length; _i++) {
178
- modules[_i] = arguments[_i];
179
- }
180
- return __awaiter(this, void 0, void 0, function () {
181
- var getHelpers, _a, modules_2, currentModule, containerModuleHelpers;
182
- return __generator(this, function (_b) {
183
- switch (_b.label) {
184
- case 0:
185
- getHelpers = this._getContainerModuleHelpersFactory();
186
- _a = 0, modules_2 = modules;
187
- _b.label = 1;
188
- case 1:
189
- if (!(_a < modules_2.length)) return [3, 4];
190
- currentModule = modules_2[_a];
191
- containerModuleHelpers = getHelpers(currentModule.id);
192
- return [4, currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction, containerModuleHelpers.unbindAsyncFunction, containerModuleHelpers.onActivationFunction, containerModuleHelpers.onDeactivationFunction)];
193
- case 2:
194
- _b.sent();
195
- _b.label = 3;
196
- case 3:
197
- _a++;
198
- return [3, 1];
199
- case 4: return [2];
200
- }
201
- });
202
- });
203
- };
204
- Container.prototype.unload = function () {
205
- var _this = this;
206
- var modules = [];
207
- for (var _i = 0; _i < arguments.length; _i++) {
208
- modules[_i] = arguments[_i];
209
- }
210
- modules.forEach(function (module) {
211
- var deactivations = _this._removeModuleBindings(module.id);
212
- _this._deactivateSingletons(deactivations);
213
- _this._removeModuleHandlers(module.id);
214
- });
215
- };
216
- Container.prototype.unloadAsync = function () {
217
- var modules = [];
218
- for (var _i = 0; _i < arguments.length; _i++) {
219
- modules[_i] = arguments[_i];
220
- }
221
- return __awaiter(this, void 0, void 0, function () {
222
- var _a, modules_3, module_1, deactivations;
223
- return __generator(this, function (_b) {
224
- switch (_b.label) {
225
- case 0:
226
- _a = 0, modules_3 = modules;
227
- _b.label = 1;
228
- case 1:
229
- if (!(_a < modules_3.length)) return [3, 4];
230
- module_1 = modules_3[_a];
231
- deactivations = this._removeModuleBindings(module_1.id);
232
- return [4, this._deactivateSingletonsAsync(deactivations)];
233
- case 2:
234
- _b.sent();
235
- this._removeModuleHandlers(module_1.id);
236
- _b.label = 3;
237
- case 3:
238
- _a++;
239
- return [3, 1];
240
- case 4: return [2];
241
- }
242
- });
128
+ }
129
+ async loadAsync(...modules) {
130
+ const getHelpers = this._getContainerModuleHelpersFactory();
131
+ for (const currentModule of modules) {
132
+ const containerModuleHelpers = getHelpers(currentModule.id);
133
+ await currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction, containerModuleHelpers.unbindAsyncFunction, containerModuleHelpers.onActivationFunction, containerModuleHelpers.onDeactivationFunction);
134
+ }
135
+ }
136
+ unload(...modules) {
137
+ modules.forEach((module) => {
138
+ const deactivations = this._removeModuleBindings(module.id);
139
+ this._deactivateSingletons(deactivations);
140
+ this._removeModuleHandlers(module.id);
243
141
  });
244
- };
245
- Container.prototype.bind = function (serviceIdentifier) {
246
- var scope = this.options.defaultScope || literal_types_1.BindingScopeEnum.Transient;
247
- var binding = new binding_1.Binding(serviceIdentifier, scope);
248
- this._bindingDictionary.add(serviceIdentifier, binding);
249
- return new binding_to_syntax_1.BindingToSyntax(binding);
250
- };
251
- Container.prototype.rebind = function (serviceIdentifier) {
142
+ }
143
+ async unloadAsync(...modules) {
144
+ for (const module of modules) {
145
+ const deactivations = this._removeModuleBindings(module.id);
146
+ await this._deactivateSingletonsAsync(deactivations);
147
+ this._removeModuleHandlers(module.id);
148
+ }
149
+ }
150
+ bind(serviceIdentifier) {
151
+ return this._bind(this._buildBinding(serviceIdentifier));
152
+ }
153
+ rebind(serviceIdentifier) {
252
154
  this.unbind(serviceIdentifier);
253
155
  return this.bind(serviceIdentifier);
254
- };
255
- Container.prototype.rebindAsync = function (serviceIdentifier) {
256
- return __awaiter(this, void 0, void 0, function () {
257
- return __generator(this, function (_a) {
258
- switch (_a.label) {
259
- case 0: return [4, this.unbindAsync(serviceIdentifier)];
260
- case 1:
261
- _a.sent();
262
- return [2, this.bind(serviceIdentifier)];
263
- }
264
- });
265
- });
266
- };
267
- Container.prototype.unbind = function (serviceIdentifier) {
156
+ }
157
+ async rebindAsync(serviceIdentifier) {
158
+ await this.unbindAsync(serviceIdentifier);
159
+ return this.bind(serviceIdentifier);
160
+ }
161
+ unbind(serviceIdentifier) {
268
162
  if (this._bindingDictionary.hasKey(serviceIdentifier)) {
269
- var bindings = this._bindingDictionary.get(serviceIdentifier);
163
+ const bindings = this._bindingDictionary.get(serviceIdentifier);
270
164
  this._deactivateSingletons(bindings);
271
165
  }
272
166
  this._removeServiceFromDictionary(serviceIdentifier);
273
- };
274
- Container.prototype.unbindAsync = function (serviceIdentifier) {
275
- return __awaiter(this, void 0, void 0, function () {
276
- var bindings;
277
- return __generator(this, function (_a) {
278
- switch (_a.label) {
279
- case 0:
280
- if (!this._bindingDictionary.hasKey(serviceIdentifier)) return [3, 2];
281
- bindings = this._bindingDictionary.get(serviceIdentifier);
282
- return [4, this._deactivateSingletonsAsync(bindings)];
283
- case 1:
284
- _a.sent();
285
- _a.label = 2;
286
- case 2:
287
- this._removeServiceFromDictionary(serviceIdentifier);
288
- return [2];
289
- }
290
- });
291
- });
292
- };
293
- Container.prototype.unbindAll = function () {
294
- var _this = this;
295
- this._bindingDictionary.traverse(function (_key, value) {
296
- _this._deactivateSingletons(value);
167
+ }
168
+ async unbindAsync(serviceIdentifier) {
169
+ if (this._bindingDictionary.hasKey(serviceIdentifier)) {
170
+ const bindings = this._bindingDictionary.get(serviceIdentifier);
171
+ await this._deactivateSingletonsAsync(bindings);
172
+ }
173
+ this._removeServiceFromDictionary(serviceIdentifier);
174
+ }
175
+ unbindAll() {
176
+ this._bindingDictionary.traverse((_key, value) => {
177
+ this._deactivateSingletons(value);
297
178
  });
298
179
  this._bindingDictionary = new lookup_1.Lookup();
299
- };
300
- Container.prototype.unbindAllAsync = function () {
301
- return __awaiter(this, void 0, void 0, function () {
302
- var promises;
303
- var _this = this;
304
- return __generator(this, function (_a) {
305
- switch (_a.label) {
306
- case 0:
307
- promises = [];
308
- this._bindingDictionary.traverse(function (_key, value) {
309
- promises.push(_this._deactivateSingletonsAsync(value));
310
- });
311
- return [4, Promise.all(promises)];
312
- case 1:
313
- _a.sent();
314
- this._bindingDictionary = new lookup_1.Lookup();
315
- return [2];
316
- }
317
- });
180
+ }
181
+ async unbindAllAsync() {
182
+ const promises = [];
183
+ this._bindingDictionary.traverse((_key, value) => {
184
+ promises.push(this._deactivateSingletonsAsync(value));
318
185
  });
319
- };
320
- Container.prototype.onActivation = function (serviceIdentifier, onActivation) {
186
+ await Promise.all(promises);
187
+ this._bindingDictionary = new lookup_1.Lookup();
188
+ }
189
+ onActivation(serviceIdentifier, onActivation) {
321
190
  this._activations.add(serviceIdentifier, onActivation);
322
- };
323
- Container.prototype.onDeactivation = function (serviceIdentifier, onDeactivation) {
191
+ }
192
+ onDeactivation(serviceIdentifier, onDeactivation) {
324
193
  this._deactivations.add(serviceIdentifier, onDeactivation);
325
- };
326
- Container.prototype.isBound = function (serviceIdentifier) {
327
- var bound = this._bindingDictionary.hasKey(serviceIdentifier);
194
+ }
195
+ isBound(serviceIdentifier) {
196
+ let bound = this._bindingDictionary.hasKey(serviceIdentifier);
328
197
  if (!bound && this.parent) {
329
198
  bound = this.parent.isBound(serviceIdentifier);
330
199
  }
331
200
  return bound;
332
- };
333
- Container.prototype.isCurrentBound = function (serviceIdentifier) {
201
+ }
202
+ isCurrentBound(serviceIdentifier) {
334
203
  return this._bindingDictionary.hasKey(serviceIdentifier);
335
- };
336
- Container.prototype.isBoundNamed = function (serviceIdentifier, named) {
204
+ }
205
+ isBoundNamed(serviceIdentifier, named) {
337
206
  return this.isBoundTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
338
- };
339
- Container.prototype.isBoundTagged = function (serviceIdentifier, key, value) {
340
- var bound = false;
207
+ }
208
+ isBoundTagged(serviceIdentifier, key, value) {
209
+ let bound = false;
341
210
  if (this._bindingDictionary.hasKey(serviceIdentifier)) {
342
- var bindings = this._bindingDictionary.get(serviceIdentifier);
343
- var request_1 = (0, planner_1.createMockRequest)(this, serviceIdentifier, key, value);
344
- bound = bindings.some(function (b) { return b.constraint(request_1); });
211
+ const bindings = this._bindingDictionary.get(serviceIdentifier);
212
+ const request = (0, planner_1.createMockRequest)(this, serviceIdentifier, key, value);
213
+ bound = bindings.some((b) => b.constraint(request));
345
214
  }
346
215
  if (!bound && this.parent) {
347
216
  bound = this.parent.isBoundTagged(serviceIdentifier, key, value);
348
217
  }
349
218
  return bound;
350
- };
351
- Container.prototype.snapshot = function () {
219
+ }
220
+ snapshot() {
352
221
  this._snapshots.push(container_snapshot_1.ContainerSnapshot.of(this._bindingDictionary.clone(), this._middleware, this._activations.clone(), this._deactivations.clone(), this._moduleActivationStore.clone()));
353
- };
354
- Container.prototype.restore = function () {
355
- var snapshot = this._snapshots.pop();
222
+ }
223
+ restore() {
224
+ const snapshot = this._snapshots.pop();
356
225
  if (snapshot === undefined) {
357
226
  throw new Error(ERROR_MSGS.NO_MORE_SNAPSHOTS_AVAILABLE);
358
227
  }
@@ -361,142 +230,104 @@ var Container = (function () {
361
230
  this._deactivations = snapshot.deactivations;
362
231
  this._middleware = snapshot.middleware;
363
232
  this._moduleActivationStore = snapshot.moduleActivationStore;
364
- };
365
- Container.prototype.createChild = function (containerOptions) {
366
- var child = new Container(containerOptions || this.options);
233
+ }
234
+ createChild(containerOptions) {
235
+ const child = new Container(containerOptions || this.options);
367
236
  child.parent = this;
368
237
  return child;
369
- };
370
- Container.prototype.applyMiddleware = function () {
371
- var middlewares = [];
372
- for (var _i = 0; _i < arguments.length; _i++) {
373
- middlewares[_i] = arguments[_i];
374
- }
375
- var initial = this._middleware
238
+ }
239
+ applyMiddleware(...middlewares) {
240
+ const initial = this._middleware
376
241
  ? this._middleware
377
242
  : this._planAndResolve();
378
- this._middleware = middlewares.reduce(function (prev, curr) { return curr(prev); }, initial);
379
- };
380
- Container.prototype.applyCustomMetadataReader = function (metadataReader) {
243
+ this._middleware = middlewares.reduce((prev, curr) => curr(prev), initial);
244
+ }
245
+ applyCustomMetadataReader(metadataReader) {
381
246
  this._metadataReader = metadataReader;
382
- };
383
- Container.prototype.get = function (serviceIdentifier) {
384
- var getArgs = this._getNotAllArgs(serviceIdentifier, false);
247
+ }
248
+ get(serviceIdentifier) {
249
+ const getArgs = this._getNotAllArgs(serviceIdentifier, false);
385
250
  return this._getButThrowIfAsync(getArgs);
386
- };
387
- Container.prototype.getAsync = function (serviceIdentifier) {
388
- return __awaiter(this, void 0, void 0, function () {
389
- var getArgs;
390
- return __generator(this, function (_a) {
391
- getArgs = this._getNotAllArgs(serviceIdentifier, false);
392
- return [2, this._get(getArgs)];
393
- });
394
- });
395
- };
396
- Container.prototype.getTagged = function (serviceIdentifier, key, value) {
397
- var getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value);
251
+ }
252
+ async getAsync(serviceIdentifier) {
253
+ const getArgs = this._getNotAllArgs(serviceIdentifier, false);
254
+ return this._get(getArgs);
255
+ }
256
+ getTagged(serviceIdentifier, key, value) {
257
+ const getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value);
398
258
  return this._getButThrowIfAsync(getArgs);
399
- };
400
- Container.prototype.getTaggedAsync = function (serviceIdentifier, key, value) {
401
- return __awaiter(this, void 0, void 0, function () {
402
- var getArgs;
403
- return __generator(this, function (_a) {
404
- getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value);
405
- return [2, this._get(getArgs)];
406
- });
407
- });
408
- };
409
- Container.prototype.getNamed = function (serviceIdentifier, named) {
259
+ }
260
+ async getTaggedAsync(serviceIdentifier, key, value) {
261
+ const getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value);
262
+ return this._get(getArgs);
263
+ }
264
+ getNamed(serviceIdentifier, named) {
410
265
  return this.getTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
411
- };
412
- Container.prototype.getNamedAsync = function (serviceIdentifier, named) {
413
- return __awaiter(this, void 0, void 0, function () {
414
- return __generator(this, function (_a) {
415
- return [2, this.getTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named)];
416
- });
417
- });
418
- };
419
- Container.prototype.getAll = function (serviceIdentifier) {
420
- var getArgs = this._getAllArgs(serviceIdentifier);
266
+ }
267
+ async getNamedAsync(serviceIdentifier, named) {
268
+ return this.getTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
269
+ }
270
+ getAll(serviceIdentifier) {
271
+ const getArgs = this._getAllArgs(serviceIdentifier);
421
272
  return this._getButThrowIfAsync(getArgs);
422
- };
423
- Container.prototype.getAllAsync = function (serviceIdentifier) {
424
- return __awaiter(this, void 0, void 0, function () {
425
- var getArgs;
426
- return __generator(this, function (_a) {
427
- getArgs = this._getAllArgs(serviceIdentifier);
428
- return [2, this._getAll(getArgs)];
429
- });
430
- });
431
- };
432
- Container.prototype.getAllTagged = function (serviceIdentifier, key, value) {
433
- var getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value);
273
+ }
274
+ async getAllAsync(serviceIdentifier) {
275
+ const getArgs = this._getAllArgs(serviceIdentifier);
276
+ return this._getAll(getArgs);
277
+ }
278
+ getAllTagged(serviceIdentifier, key, value) {
279
+ const getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value);
434
280
  return this._getButThrowIfAsync(getArgs);
435
- };
436
- Container.prototype.getAllTaggedAsync = function (serviceIdentifier, key, value) {
437
- return __awaiter(this, void 0, void 0, function () {
438
- var getArgs;
439
- return __generator(this, function (_a) {
440
- getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value);
441
- return [2, this._getAll(getArgs)];
442
- });
443
- });
444
- };
445
- Container.prototype.getAllNamed = function (serviceIdentifier, named) {
281
+ }
282
+ async getAllTaggedAsync(serviceIdentifier, key, value) {
283
+ const getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value);
284
+ return this._getAll(getArgs);
285
+ }
286
+ getAllNamed(serviceIdentifier, named) {
446
287
  return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
447
- };
448
- Container.prototype.getAllNamedAsync = function (serviceIdentifier, named) {
449
- return __awaiter(this, void 0, void 0, function () {
450
- return __generator(this, function (_a) {
451
- return [2, this.getAllTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named)];
452
- });
453
- });
454
- };
455
- Container.prototype.resolve = function (constructorFunction) {
456
- var isBound = this.isBound(constructorFunction);
288
+ }
289
+ async getAllNamedAsync(serviceIdentifier, named) {
290
+ return this.getAllTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
291
+ }
292
+ resolve(constructorFunction) {
293
+ const isBound = this.isBound(constructorFunction);
457
294
  if (!isBound) {
458
295
  this.bind(constructorFunction).toSelf();
459
296
  }
460
- var resolved = this.get(constructorFunction);
297
+ const resolved = this.get(constructorFunction);
461
298
  if (!isBound) {
462
299
  this.unbind(constructorFunction);
463
300
  }
464
301
  return resolved;
465
- };
466
- Container.prototype._preDestroy = function (constructor, instance) {
467
- var _a, _b;
302
+ }
303
+ _preDestroy(constructor, instance) {
468
304
  if (constructor !== undefined &&
469
305
  Reflect.hasMetadata(METADATA_KEY.PRE_DESTROY, constructor)) {
470
- var data = Reflect.getMetadata(METADATA_KEY.PRE_DESTROY, constructor);
471
- return (_b = (_a = instance)[data.value]) === null || _b === void 0 ? void 0 : _b.call(_a);
306
+ const data = Reflect.getMetadata(METADATA_KEY.PRE_DESTROY, constructor);
307
+ return instance[data.value]?.();
472
308
  }
473
- };
474
- Container.prototype._removeModuleHandlers = function (moduleId) {
475
- var moduleActivationsHandlers = this._moduleActivationStore.remove(moduleId);
309
+ }
310
+ _removeModuleHandlers(moduleId) {
311
+ const moduleActivationsHandlers = this._moduleActivationStore.remove(moduleId);
476
312
  this._activations.removeIntersection(moduleActivationsHandlers.onActivations);
477
313
  this._deactivations.removeIntersection(moduleActivationsHandlers.onDeactivations);
478
- };
479
- Container.prototype._removeModuleBindings = function (moduleId) {
480
- return this._bindingDictionary.removeByCondition(function (binding) { return binding.moduleId === moduleId; });
481
- };
482
- Container.prototype._deactivate = function (binding, instance) {
483
- var _this = this;
484
- var constructor = instance == undefined
314
+ }
315
+ _removeModuleBindings(moduleId) {
316
+ return this._bindingDictionary.removeByCondition((binding) => binding.moduleId === moduleId);
317
+ }
318
+ _deactivate(binding, instance) {
319
+ const constructor = instance == undefined
485
320
  ? undefined
486
321
  :
487
322
  Object.getPrototypeOf(instance).constructor;
488
323
  try {
489
324
  if (this._deactivations.hasKey(binding.serviceIdentifier)) {
490
- var result = this._deactivateContainer(instance, this._deactivations.get(binding.serviceIdentifier).values());
325
+ const result = this._deactivateContainer(instance, this._deactivations.get(binding.serviceIdentifier).values());
491
326
  if ((0, async_1.isPromise)(result)) {
492
- return this._handleDeactivationError(result.then(function () { return __awaiter(_this, void 0, void 0, function () {
493
- return __generator(this, function (_a) {
494
- return [2, this._propagateContainerDeactivationThenBindingAndPreDestroyAsync(binding, instance, constructor)];
495
- });
496
- }); }), binding.serviceIdentifier);
327
+ return this._handleDeactivationError(result.then(async () => this._propagateContainerDeactivationThenBindingAndPreDestroyAsync(binding, instance, constructor)), binding.serviceIdentifier);
497
328
  }
498
329
  }
499
- var propagateDeactivationResult = this._propagateContainerDeactivationThenBindingAndPreDestroy(binding, instance, constructor);
330
+ const propagateDeactivationResult = this._propagateContainerDeactivationThenBindingAndPreDestroy(binding, instance, constructor);
500
331
  if ((0, async_1.isPromise)(propagateDeactivationResult)) {
501
332
  return this._handleDeactivationError(propagateDeactivationResult, binding.serviceIdentifier);
502
333
  }
@@ -506,109 +337,65 @@ var Container = (function () {
506
337
  throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR((0, serialization_1.getServiceIdentifierAsString)(binding.serviceIdentifier), ex.message));
507
338
  }
508
339
  }
509
- };
510
- Container.prototype._handleDeactivationError = function (asyncResult, serviceIdentifier) {
511
- return __awaiter(this, void 0, void 0, function () {
512
- var ex_1;
513
- return __generator(this, function (_a) {
514
- switch (_a.label) {
515
- case 0:
516
- _a.trys.push([0, 2, , 3]);
517
- return [4, asyncResult];
518
- case 1:
519
- _a.sent();
520
- return [3, 3];
521
- case 2:
522
- ex_1 = _a.sent();
523
- if (ex_1 instanceof Error) {
524
- throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR((0, serialization_1.getServiceIdentifierAsString)(serviceIdentifier), ex_1.message));
525
- }
526
- return [3, 3];
527
- case 3: return [2];
528
- }
529
- });
530
- });
531
- };
532
- Container.prototype._deactivateContainer = function (instance, deactivationsIterator) {
533
- var _this = this;
534
- var deactivation = deactivationsIterator.next();
340
+ }
341
+ async _handleDeactivationError(asyncResult, serviceIdentifier) {
342
+ try {
343
+ await asyncResult;
344
+ }
345
+ catch (ex) {
346
+ if (ex instanceof Error) {
347
+ throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR((0, serialization_1.getServiceIdentifierAsString)(serviceIdentifier), ex.message));
348
+ }
349
+ }
350
+ }
351
+ _deactivateContainer(instance, deactivationsIterator) {
352
+ let deactivation = deactivationsIterator.next();
535
353
  while (typeof deactivation.value === 'function') {
536
- var result = deactivation.value(instance);
354
+ const result = deactivation.value(instance);
537
355
  if ((0, async_1.isPromise)(result)) {
538
- return result.then(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
539
- return [2, this._deactivateContainerAsync(instance, deactivationsIterator)];
540
- }); }); });
356
+ return result.then(async () => this._deactivateContainerAsync(instance, deactivationsIterator));
541
357
  }
542
358
  deactivation = deactivationsIterator.next();
543
359
  }
544
- };
545
- Container.prototype._deactivateContainerAsync = function (instance, deactivationsIterator) {
546
- return __awaiter(this, void 0, void 0, function () {
547
- var deactivation;
548
- return __generator(this, function (_a) {
549
- switch (_a.label) {
550
- case 0:
551
- deactivation = deactivationsIterator.next();
552
- _a.label = 1;
553
- case 1:
554
- if (!(typeof deactivation.value === 'function')) return [3, 3];
555
- return [4, deactivation.value(instance)];
556
- case 2:
557
- _a.sent();
558
- deactivation = deactivationsIterator.next();
559
- return [3, 1];
560
- case 3: return [2];
561
- }
562
- });
563
- });
564
- };
565
- Container.prototype._getContainerModuleHelpersFactory = function () {
566
- var _this = this;
567
- var setModuleId = function (bindingToSyntax, moduleId) {
568
- bindingToSyntax._binding.moduleId = moduleId;
360
+ }
361
+ async _deactivateContainerAsync(instance, deactivationsIterator) {
362
+ let deactivation = deactivationsIterator.next();
363
+ while (typeof deactivation.value === 'function') {
364
+ await deactivation.value(instance);
365
+ deactivation = deactivationsIterator.next();
366
+ }
367
+ }
368
+ _getContainerModuleHelpersFactory() {
369
+ const getBindFunction = (moduleId) => (serviceIdentifier) => {
370
+ const binding = this._buildBinding(serviceIdentifier);
371
+ binding.moduleId = moduleId;
372
+ return this._bind(binding);
569
373
  };
570
- var getBindFunction = function (moduleId) {
571
- return function (serviceIdentifier) {
572
- var bindingToSyntax = _this.bind(serviceIdentifier);
573
- setModuleId(bindingToSyntax, moduleId);
574
- return bindingToSyntax;
575
- };
374
+ const getUnbindFunction = () => (serviceIdentifier) => {
375
+ this.unbind(serviceIdentifier);
576
376
  };
577
- var getUnbindFunction = function () { return function (serviceIdentifier) {
578
- _this.unbind(serviceIdentifier);
579
- }; };
580
- var getUnbindAsyncFunction = function () {
581
- return function (serviceIdentifier) { return __awaiter(_this, void 0, void 0, function () {
582
- return __generator(this, function (_a) {
583
- return [2, this.unbindAsync(serviceIdentifier)];
584
- });
585
- }); };
377
+ const getUnbindAsyncFunction = () => async (serviceIdentifier) => {
378
+ return this.unbindAsync(serviceIdentifier);
586
379
  };
587
- var getIsboundFunction = function () {
588
- return function (serviceIdentifier) {
589
- return _this.isBound(serviceIdentifier);
590
- };
380
+ const getIsboundFunction = () => (serviceIdentifier) => {
381
+ return this.isBound(serviceIdentifier);
591
382
  };
592
- var getRebindFunction = function (moduleId) {
593
- return function (serviceIdentifier) {
594
- var bindingToSyntax = _this.rebind(serviceIdentifier);
595
- setModuleId(bindingToSyntax, moduleId);
596
- return bindingToSyntax;
383
+ const getRebindFunction = (moduleId) => {
384
+ const bind = getBindFunction(moduleId);
385
+ return (serviceIdentifier) => {
386
+ this.unbind(serviceIdentifier);
387
+ return bind(serviceIdentifier);
597
388
  };
598
389
  };
599
- var getOnActivationFunction = function (moduleId) {
600
- return function (serviceIdentifier, onActivation) {
601
- _this._moduleActivationStore.addActivation(moduleId, serviceIdentifier, onActivation);
602
- _this.onActivation(serviceIdentifier, onActivation);
603
- };
390
+ const getOnActivationFunction = (moduleId) => (serviceIdentifier, onActivation) => {
391
+ this._moduleActivationStore.addActivation(moduleId, serviceIdentifier, onActivation);
392
+ this.onActivation(serviceIdentifier, onActivation);
604
393
  };
605
- var getOnDeactivationFunction = function (moduleId) {
606
- return function (serviceIdentifier, onDeactivation) {
607
- _this._moduleActivationStore.addDeactivation(moduleId, serviceIdentifier, onDeactivation);
608
- _this.onDeactivation(serviceIdentifier, onDeactivation);
609
- };
394
+ const getOnDeactivationFunction = (moduleId) => (serviceIdentifier, onDeactivation) => {
395
+ this._moduleActivationStore.addDeactivation(moduleId, serviceIdentifier, onDeactivation);
396
+ this.onDeactivation(serviceIdentifier, onDeactivation);
610
397
  };
611
- return function (mId) { return ({
398
+ return (mId) => ({
612
399
  bindFunction: getBindFunction(mId),
613
400
  isboundFunction: getIsboundFunction(),
614
401
  onActivationFunction: getOnActivationFunction(mId),
@@ -616,161 +403,125 @@ var Container = (function () {
616
403
  rebindFunction: getRebindFunction(mId),
617
404
  unbindAsyncFunction: getUnbindAsyncFunction(),
618
405
  unbindFunction: getUnbindFunction(),
619
- }); };
620
- };
621
- Container.prototype._getAll = function (getArgs) {
622
- return __awaiter(this, void 0, void 0, function () {
623
- return __generator(this, function (_a) {
624
- return [2, Promise.all(this._get(getArgs))];
625
- });
626
406
  });
627
- };
628
- Container.prototype._get = function (getArgs) {
629
- var planAndResolveArgs = __assign(__assign({}, getArgs), { contextInterceptor: function (context) { return context; }, targetType: literal_types_1.TargetTypeEnum.Variable });
407
+ }
408
+ _bind(binding) {
409
+ this._bindingDictionary.add(binding.serviceIdentifier, binding);
410
+ return new binding_to_syntax_1.BindingToSyntax(binding);
411
+ }
412
+ _buildBinding(serviceIdentifier) {
413
+ const scope = this.options.defaultScope || literal_types_1.BindingScopeEnum.Transient;
414
+ return new binding_1.Binding(serviceIdentifier, scope);
415
+ }
416
+ async _getAll(getArgs) {
417
+ return Promise.all(this._get(getArgs));
418
+ }
419
+ _get(getArgs) {
420
+ const planAndResolveArgs = {
421
+ ...getArgs,
422
+ contextInterceptor: (context) => context,
423
+ targetType: literal_types_1.TargetTypeEnum.Variable,
424
+ };
630
425
  if (this._middleware) {
631
- var middlewareResult = this._middleware(planAndResolveArgs);
426
+ const middlewareResult = this._middleware(planAndResolveArgs);
632
427
  if (middlewareResult === undefined || middlewareResult === null) {
633
428
  throw new Error(ERROR_MSGS.INVALID_MIDDLEWARE_RETURN);
634
429
  }
635
430
  return middlewareResult;
636
431
  }
637
432
  return this._planAndResolve()(planAndResolveArgs);
638
- };
639
- Container.prototype._getButThrowIfAsync = function (getArgs) {
640
- var result = this._get(getArgs);
433
+ }
434
+ _getButThrowIfAsync(getArgs) {
435
+ const result = this._get(getArgs);
641
436
  if ((0, async_1.isPromiseOrContainsPromise)(result)) {
642
437
  throw new Error(ERROR_MSGS.LAZY_IN_SYNC(getArgs.serviceIdentifier));
643
438
  }
644
439
  return result;
645
- };
646
- Container.prototype._getAllArgs = function (serviceIdentifier) {
647
- var getAllArgs = {
440
+ }
441
+ _getAllArgs(serviceIdentifier) {
442
+ const getAllArgs = {
648
443
  avoidConstraints: true,
649
444
  isMultiInject: true,
650
- serviceIdentifier: serviceIdentifier,
445
+ serviceIdentifier,
651
446
  };
652
447
  return getAllArgs;
653
- };
654
- Container.prototype._getNotAllArgs = function (serviceIdentifier, isMultiInject, key, value) {
655
- var getNotAllArgs = {
448
+ }
449
+ _getNotAllArgs(serviceIdentifier, isMultiInject, key, value) {
450
+ const getNotAllArgs = {
656
451
  avoidConstraints: false,
657
- isMultiInject: isMultiInject,
658
- key: key,
659
- serviceIdentifier: serviceIdentifier,
660
- value: value,
452
+ isMultiInject,
453
+ key,
454
+ serviceIdentifier,
455
+ value,
661
456
  };
662
457
  return getNotAllArgs;
663
- };
664
- Container.prototype._planAndResolve = function () {
665
- var _this = this;
666
- return function (args) {
667
- var context = (0, planner_1.plan)(_this._metadataReader, _this, args.isMultiInject, args.targetType, args.serviceIdentifier, args.key, args.value, args.avoidConstraints);
458
+ }
459
+ _planAndResolve() {
460
+ return (args) => {
461
+ let context = (0, planner_1.plan)(this._metadataReader, this, args.isMultiInject, args.targetType, args.serviceIdentifier, args.key, args.value, args.avoidConstraints);
668
462
  context = args.contextInterceptor(context);
669
- var result = (0, resolver_1.resolve)(context);
463
+ const result = (0, resolver_1.resolve)(context);
670
464
  return result;
671
465
  };
672
- };
673
- Container.prototype._deactivateIfSingleton = function (binding) {
674
- var _this = this;
466
+ }
467
+ _deactivateIfSingleton(binding) {
675
468
  if (!binding.activated) {
676
469
  return;
677
470
  }
678
471
  if ((0, async_1.isPromise)(binding.cache)) {
679
- return binding.cache.then(function (resolved) {
680
- return _this._deactivate(binding, resolved);
681
- });
472
+ return binding.cache.then((resolved) => this._deactivate(binding, resolved));
682
473
  }
683
474
  return this._deactivate(binding, binding.cache);
684
- };
685
- Container.prototype._deactivateSingletons = function (bindings) {
686
- for (var _i = 0, bindings_1 = bindings; _i < bindings_1.length; _i++) {
687
- var binding = bindings_1[_i];
688
- var result = this._deactivateIfSingleton(binding);
475
+ }
476
+ _deactivateSingletons(bindings) {
477
+ for (const binding of bindings) {
478
+ const result = this._deactivateIfSingleton(binding);
689
479
  if ((0, async_1.isPromise)(result)) {
690
480
  throw new Error(ERROR_MSGS.ASYNC_UNBIND_REQUIRED);
691
481
  }
692
482
  }
693
- };
694
- Container.prototype._deactivateSingletonsAsync = function (bindings) {
695
- return __awaiter(this, void 0, void 0, function () {
696
- var _this = this;
697
- return __generator(this, function (_a) {
698
- switch (_a.label) {
699
- case 0: return [4, Promise.all(bindings.map(function (b) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
700
- return [2, this._deactivateIfSingleton(b)];
701
- }); }); }))];
702
- case 1:
703
- _a.sent();
704
- return [2];
705
- }
706
- });
707
- });
708
- };
709
- Container.prototype._propagateContainerDeactivationThenBindingAndPreDestroy = function (binding, instance, constructor) {
483
+ }
484
+ async _deactivateSingletonsAsync(bindings) {
485
+ await Promise.all(bindings.map(async (b) => this._deactivateIfSingleton(b)));
486
+ }
487
+ _propagateContainerDeactivationThenBindingAndPreDestroy(binding, instance, constructor) {
710
488
  if (this.parent) {
711
489
  return this._deactivate.bind(this.parent)(binding, instance);
712
490
  }
713
491
  else {
714
492
  return this._bindingDeactivationAndPreDestroy(binding, instance, constructor);
715
493
  }
716
- };
717
- Container.prototype._propagateContainerDeactivationThenBindingAndPreDestroyAsync = function (binding, instance, constructor) {
718
- return __awaiter(this, void 0, void 0, function () {
719
- return __generator(this, function (_a) {
720
- switch (_a.label) {
721
- case 0:
722
- if (!this.parent) return [3, 2];
723
- return [4, this._deactivate.bind(this.parent)(binding, instance)];
724
- case 1:
725
- _a.sent();
726
- return [3, 4];
727
- case 2: return [4, this._bindingDeactivationAndPreDestroyAsync(binding, instance, constructor)];
728
- case 3:
729
- _a.sent();
730
- _a.label = 4;
731
- case 4: return [2];
732
- }
733
- });
734
- });
735
- };
736
- Container.prototype._removeServiceFromDictionary = function (serviceIdentifier) {
494
+ }
495
+ async _propagateContainerDeactivationThenBindingAndPreDestroyAsync(binding, instance, constructor) {
496
+ if (this.parent) {
497
+ await this._deactivate.bind(this.parent)(binding, instance);
498
+ }
499
+ else {
500
+ await this._bindingDeactivationAndPreDestroyAsync(binding, instance, constructor);
501
+ }
502
+ }
503
+ _removeServiceFromDictionary(serviceIdentifier) {
737
504
  try {
738
505
  this._bindingDictionary.remove(serviceIdentifier);
739
506
  }
740
507
  catch (_e) {
741
- throw new Error("".concat(ERROR_MSGS.CANNOT_UNBIND, " ").concat((0, serialization_1.getServiceIdentifierAsString)(serviceIdentifier)));
508
+ throw new Error(`${ERROR_MSGS.CANNOT_UNBIND} ${(0, serialization_1.getServiceIdentifierAsString)(serviceIdentifier)}`);
742
509
  }
743
- };
744
- Container.prototype._bindingDeactivationAndPreDestroy = function (binding, instance, constructor) {
745
- var _this = this;
510
+ }
511
+ _bindingDeactivationAndPreDestroy(binding, instance, constructor) {
746
512
  if (typeof binding.onDeactivation === 'function') {
747
- var result = binding.onDeactivation(instance);
513
+ const result = binding.onDeactivation(instance);
748
514
  if ((0, async_1.isPromise)(result)) {
749
- return result.then(function () {
750
- return _this._preDestroy(constructor, instance);
751
- });
515
+ return result.then(() => this._preDestroy(constructor, instance));
752
516
  }
753
517
  }
754
518
  return this._preDestroy(constructor, instance);
755
- };
756
- Container.prototype._bindingDeactivationAndPreDestroyAsync = function (binding, instance, constructor) {
757
- return __awaiter(this, void 0, void 0, function () {
758
- return __generator(this, function (_a) {
759
- switch (_a.label) {
760
- case 0:
761
- if (!(typeof binding.onDeactivation === 'function')) return [3, 2];
762
- return [4, binding.onDeactivation(instance)];
763
- case 1:
764
- _a.sent();
765
- _a.label = 2;
766
- case 2: return [4, this._preDestroy(constructor, instance)];
767
- case 3:
768
- _a.sent();
769
- return [2];
770
- }
771
- });
772
- });
773
- };
774
- return Container;
775
- }());
519
+ }
520
+ async _bindingDeactivationAndPreDestroyAsync(binding, instance, constructor) {
521
+ if (typeof binding.onDeactivation === 'function') {
522
+ await binding.onDeactivation(instance);
523
+ }
524
+ await this._preDestroy(constructor, instance);
525
+ }
526
+ }
776
527
  exports.Container = Container;