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.
- package/CHANGELOG.md +11 -1
- package/README.md +6 -15
- package/es/container/container.d.ts +2 -0
- package/es/container/module_activation_store.d.ts +2 -2
- package/es/interfaces/interfaces.d.ts +2 -2
- package/es/inversify.d.ts +1 -0
- package/es/inversify.js +3 -2
- package/es/inversify.js.LICENSE.txt +14 -0
- package/lib/annotation/decorator_utils.js +31 -25
- package/lib/annotation/inject.js +20 -10
- package/lib/annotation/inject_base.js +6 -6
- package/lib/annotation/injectable.js +20 -10
- package/lib/annotation/multi_inject.js +20 -10
- package/lib/annotation/named.js +20 -10
- package/lib/annotation/optional.js +20 -10
- package/lib/annotation/post_construct.js +21 -11
- package/lib/annotation/pre_destroy.js +21 -11
- package/lib/annotation/property_event_decorator.js +4 -4
- package/lib/annotation/tagged.js +2 -2
- package/lib/annotation/target_name.js +21 -11
- package/lib/annotation/unmanaged.js +21 -11
- package/lib/bindings/binding.js +23 -10
- package/lib/constants/error_msgs.js +15 -29
- package/lib/constants/literal_types.js +3 -3
- package/lib/container/container.d.ts +2 -0
- package/lib/container/container.js +317 -566
- package/lib/container/container_module.js +11 -9
- package/lib/container/container_snapshot.js +10 -8
- package/lib/container/lookup.js +61 -56
- package/lib/container/module_activation_store.d.ts +2 -2
- package/lib/container/module_activation_store.js +21 -24
- package/lib/interfaces/interfaces.d.ts +2 -2
- package/lib/inversify.d.ts +1 -0
- package/lib/inversify.js +19 -8
- package/lib/planning/context.js +12 -9
- package/lib/planning/metadata.js +27 -16
- package/lib/planning/metadata_reader.js +29 -24
- package/lib/planning/plan.js +5 -4
- package/lib/planning/planner.js +62 -53
- package/lib/planning/queryable_string.js +16 -16
- package/lib/planning/reflection_utils.js +25 -17
- package/lib/planning/request.js +15 -8
- package/lib/resolution/instantiation.js +59 -119
- package/lib/resolution/resolver.js +89 -134
- package/lib/scope/scope.js +17 -62
- package/lib/syntax/binding_in_syntax.js +12 -12
- package/lib/syntax/binding_in_when_on_syntax.js +50 -47
- package/lib/syntax/binding_on_syntax.js +9 -9
- package/lib/syntax/binding_to_syntax.js +70 -49
- package/lib/syntax/binding_when_on_syntax.js +42 -40
- package/lib/syntax/binding_when_syntax.js +54 -76
- package/lib/syntax/constraint_helpers.js +31 -23
- package/lib/utils/async.js +1 -1
- package/lib/utils/binding_utils.js +31 -29
- package/lib/utils/exceptions.js +19 -9
- package/lib/utils/id.js +1 -1
- package/lib/utils/js.js +2 -3
- package/lib/utils/serialization.js +42 -33
- package/package.json +14 -15
- package/amd/annotation/decorator_utils.d.ts +0 -16
- package/amd/annotation/decorator_utils.js +0 -119
- package/amd/annotation/inject.d.ts +0 -5
- package/amd/annotation/inject.js +0 -31
- package/amd/annotation/inject_base.d.ts +0 -4
- package/amd/annotation/inject_base.js +0 -16
- package/amd/annotation/injectable.d.ts +0 -2
- package/amd/annotation/injectable.js +0 -40
- package/amd/annotation/lazy_service_identifier.js +0 -4
- package/amd/annotation/multi_inject.d.ts +0 -5
- package/amd/annotation/multi_inject.js +0 -31
- package/amd/annotation/named.d.ts +0 -2
- package/amd/annotation/named.js +0 -32
- package/amd/annotation/optional.d.ts +0 -2
- package/amd/annotation/optional.js +0 -32
- package/amd/annotation/post_construct.d.ts +0 -4
- package/amd/annotation/post_construct.js +0 -32
- package/amd/annotation/pre_destroy.d.ts +0 -4
- package/amd/annotation/pre_destroy.js +0 -32
- package/amd/annotation/property_event_decorator.d.ts +0 -4
- package/amd/annotation/property_event_decorator.js +0 -16
- package/amd/annotation/tagged.d.ts +0 -2
- package/amd/annotation/tagged.js +0 -8
- package/amd/annotation/target_name.d.ts +0 -3
- package/amd/annotation/target_name.js +0 -35
- package/amd/annotation/unmanaged.d.ts +0 -3
- package/amd/annotation/unmanaged.js +0 -35
- package/amd/bindings/binding.d.ts +0 -20
- package/amd/bindings/binding.js +0 -40
- package/amd/bindings/binding_count.d.ts +0 -5
- package/amd/bindings/binding_count.js +0 -11
- package/amd/constants/error_msgs.d.ts +0 -30
- package/amd/constants/error_msgs.js +0 -75
- package/amd/constants/literal_types.d.ts +0 -5
- package/amd/constants/literal_types.js +0 -28
- package/amd/constants/metadata_keys.d.ts +0 -13
- package/amd/constants/metadata_keys.js +0 -28
- package/amd/container/container.d.ts +0 -73
- package/amd/container/container.js +0 -766
- package/amd/container/container_module.d.ts +0 -11
- package/amd/container/container_module.js +0 -21
- package/amd/container/container_snapshot.d.ts +0 -10
- package/amd/container/container_snapshot.js +0 -20
- package/amd/container/lookup.d.ts +0 -17
- package/amd/container/lookup.js +0 -132
- package/amd/container/module_activation_store.d.ts +0 -10
- package/amd/container/module_activation_store.js +0 -51
- package/amd/interfaces/interfaces.d.ts +0 -269
- package/amd/interfaces/interfaces.js +0 -4
- package/amd/inversify.d.ts +0 -24
- package/amd/inversify.js +0 -57
- package/amd/planning/context.d.ts +0 -11
- package/amd/planning/context.js +0 -19
- package/amd/planning/metadata.d.ts +0 -8
- package/amd/planning/metadata.js +0 -45
- package/amd/planning/metadata_reader.d.ts +0 -6
- package/amd/planning/metadata_reader.js +0 -49
- package/amd/planning/plan.d.ts +0 -7
- package/amd/planning/plan.js +0 -13
- package/amd/planning/planner.d.ts +0 -5
- package/amd/planning/planner.js +0 -187
- package/amd/planning/queryable_string.d.ts +0 -10
- package/amd/planning/queryable_string.js +0 -33
- package/amd/planning/reflection_utils.d.ts +0 -5
- package/amd/planning/reflection_utils.js +0 -55
- package/amd/planning/request.d.ts +0 -14
- package/amd/planning/request.js +0 -24
- package/amd/planning/target.js +0 -111
- package/amd/resolution/instantiation.d.ts +0 -3
- package/amd/resolution/instantiation.js +0 -219
- package/amd/resolution/resolver.d.ts +0 -3
- package/amd/resolution/resolver.js +0 -234
- package/amd/scope/scope.d.ts +0 -3
- package/amd/scope/scope.js +0 -93
- package/amd/syntax/binding_in_syntax.d.ts +0 -9
- package/amd/syntax/binding_in_syntax.js +0 -24
- package/amd/syntax/binding_in_when_on_syntax.d.ts +0 -29
- package/amd/syntax/binding_in_when_on_syntax.js +0 -75
- package/amd/syntax/binding_on_syntax.d.ts +0 -8
- package/amd/syntax/binding_on_syntax.js +0 -20
- package/amd/syntax/binding_to_syntax.d.ts +0 -18
- package/amd/syntax/binding_to_syntax.js +0 -116
- package/amd/syntax/binding_when_on_syntax.d.ts +0 -25
- package/amd/syntax/binding_when_on_syntax.js +0 -65
- package/amd/syntax/binding_when_syntax.d.ts +0 -21
- package/amd/syntax/binding_when_syntax.js +0 -107
- package/amd/syntax/constraint_helpers.d.ts +0 -6
- package/amd/syntax/constraint_helpers.js +0 -66
- package/amd/utils/async.d.ts +0 -3
- package/amd/utils/async.js +0 -17
- package/amd/utils/binding_utils.d.ts +0 -4
- package/amd/utils/binding_utils.js +0 -86
- package/amd/utils/clonable.d.ts +0 -3
- package/amd/utils/clonable.js +0 -11
- package/amd/utils/exceptions.d.ts +0 -2
- package/amd/utils/exceptions.js +0 -46
- package/amd/utils/factory_type.d.ts +0 -5
- package/amd/utils/factory_type.js +0 -11
- package/amd/utils/id.d.ts +0 -2
- package/amd/utils/id.js +0 -9
- package/amd/utils/js.d.ts +0 -1
- package/amd/utils/js.js +0 -18
- package/amd/utils/serialization.d.ts +0 -10
- package/amd/utils/serialization.js +0 -135
- package/es6/annotation/decorator_utils.d.ts +0 -16
- package/es6/annotation/decorator_utils.js +0 -114
- package/es6/annotation/inject.d.ts +0 -5
- package/es6/annotation/inject.js +0 -30
- package/es6/annotation/inject_base.d.ts +0 -4
- package/es6/annotation/inject_base.js +0 -17
- package/es6/annotation/injectable.d.ts +0 -2
- package/es6/annotation/injectable.js +0 -38
- package/es6/annotation/lazy_service_identifier.js +0 -2
- package/es6/annotation/multi_inject.d.ts +0 -5
- package/es6/annotation/multi_inject.js +0 -30
- package/es6/annotation/named.d.ts +0 -2
- package/es6/annotation/named.js +0 -32
- package/es6/annotation/optional.d.ts +0 -2
- package/es6/annotation/optional.js +0 -32
- package/es6/annotation/post_construct.d.ts +0 -4
- package/es6/annotation/post_construct.js +0 -31
- package/es6/annotation/pre_destroy.d.ts +0 -4
- package/es6/annotation/pre_destroy.js +0 -31
- package/es6/annotation/property_event_decorator.d.ts +0 -4
- package/es6/annotation/property_event_decorator.js +0 -15
- package/es6/annotation/tagged.d.ts +0 -2
- package/es6/annotation/tagged.js +0 -8
- package/es6/annotation/target_name.d.ts +0 -3
- package/es6/annotation/target_name.js +0 -35
- package/es6/annotation/unmanaged.d.ts +0 -3
- package/es6/annotation/unmanaged.js +0 -35
- package/es6/bindings/binding.d.ts +0 -20
- package/es6/bindings/binding.js +0 -39
- package/es6/bindings/binding_count.d.ts +0 -5
- package/es6/bindings/binding_count.js +0 -9
- package/es6/constants/error_msgs.d.ts +0 -30
- package/es6/constants/error_msgs.js +0 -59
- package/es6/constants/literal_types.d.ts +0 -5
- package/es6/constants/literal_types.js +0 -26
- package/es6/constants/metadata_keys.d.ts +0 -13
- package/es6/constants/metadata_keys.js +0 -26
- package/es6/container/container.d.ts +0 -73
- package/es6/container/container.js +0 -545
- package/es6/container/container_module.d.ts +0 -11
- package/es6/container/container_module.js +0 -18
- package/es6/container/container_snapshot.d.ts +0 -10
- package/es6/container/container_snapshot.js +0 -15
- package/es6/container/lookup.d.ts +0 -17
- package/es6/container/lookup.js +0 -125
- package/es6/container/module_activation_store.d.ts +0 -10
- package/es6/container/module_activation_store.js +0 -49
- package/es6/interfaces/interfaces.d.ts +0 -269
- package/es6/interfaces/interfaces.js +0 -2
- package/es6/inversify.d.ts +0 -24
- package/es6/inversify.js +0 -76
- package/es6/planning/context.d.ts +0 -11
- package/es6/planning/context.js +0 -17
- package/es6/planning/metadata.d.ts +0 -8
- package/es6/planning/metadata.js +0 -42
- package/es6/planning/metadata_reader.d.ts +0 -6
- package/es6/planning/metadata_reader.js +0 -44
- package/es6/planning/plan.d.ts +0 -7
- package/es6/planning/plan.js +0 -10
- package/es6/planning/planner.d.ts +0 -5
- package/es6/planning/planner.js +0 -194
- package/es6/planning/queryable_string.d.ts +0 -10
- package/es6/planning/queryable_string.js +0 -30
- package/es6/planning/reflection_utils.d.ts +0 -5
- package/es6/planning/reflection_utils.js +0 -53
- package/es6/planning/request.d.ts +0 -14
- package/es6/planning/request.js +0 -22
- package/es6/planning/target.js +0 -105
- package/es6/resolution/instantiation.d.ts +0 -3
- package/es6/resolution/instantiation.js +0 -158
- package/es6/resolution/resolver.d.ts +0 -3
- package/es6/resolution/resolver.js +0 -193
- package/es6/scope/scope.d.ts +0 -3
- package/es6/scope/scope.js +0 -57
- package/es6/syntax/binding_in_syntax.d.ts +0 -9
- package/es6/syntax/binding_in_syntax.js +0 -23
- package/es6/syntax/binding_in_when_on_syntax.d.ts +0 -29
- package/es6/syntax/binding_in_when_on_syntax.js +0 -75
- package/es6/syntax/binding_on_syntax.d.ts +0 -8
- package/es6/syntax/binding_on_syntax.js +0 -18
- package/es6/syntax/binding_to_syntax.d.ts +0 -18
- package/es6/syntax/binding_to_syntax.js +0 -110
- package/es6/syntax/binding_when_on_syntax.d.ts +0 -25
- package/es6/syntax/binding_when_on_syntax.js +0 -64
- package/es6/syntax/binding_when_syntax.d.ts +0 -21
- package/es6/syntax/binding_when_syntax.js +0 -84
- package/es6/syntax/constraint_helpers.d.ts +0 -6
- package/es6/syntax/constraint_helpers.js +0 -63
- package/es6/utils/async.d.ts +0 -3
- package/es6/utils/async.js +0 -15
- package/es6/utils/binding_utils.d.ts +0 -4
- package/es6/utils/binding_utils.js +0 -79
- package/es6/utils/clonable.d.ts +0 -3
- package/es6/utils/clonable.js +0 -9
- package/es6/utils/exceptions.d.ts +0 -2
- package/es6/utils/exceptions.js +0 -44
- package/es6/utils/factory_type.d.ts +0 -5
- package/es6/utils/factory_type.js +0 -9
- package/es6/utils/id.d.ts +0 -2
- package/es6/utils/id.js +0 -7
- package/es6/utils/js.d.ts +0 -1
- package/es6/utils/js.js +0 -15
- package/es6/utils/serialization.d.ts +0 -10
- 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 (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
45
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
148
|
-
|
|
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(
|
|
153
|
-
value.forEach(
|
|
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(
|
|
117
|
+
targetContainers.forEach((targetBindingDictionary) => {
|
|
159
118
|
copyDictionary(targetBindingDictionary, bindingDictionary);
|
|
160
119
|
});
|
|
161
120
|
return container;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
for (
|
|
166
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
for (
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
163
|
+
const bindings = this._bindingDictionary.get(serviceIdentifier);
|
|
270
164
|
this._deactivateSingletons(bindings);
|
|
271
165
|
}
|
|
272
166
|
this._removeServiceFromDictionary(serviceIdentifier);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
|
|
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
|
-
|
|
191
|
+
}
|
|
192
|
+
onDeactivation(serviceIdentifier, onDeactivation) {
|
|
324
193
|
this._deactivations.add(serviceIdentifier, onDeactivation);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
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
|
-
|
|
201
|
+
}
|
|
202
|
+
isCurrentBound(serviceIdentifier) {
|
|
334
203
|
return this._bindingDictionary.hasKey(serviceIdentifier);
|
|
335
|
-
}
|
|
336
|
-
|
|
204
|
+
}
|
|
205
|
+
isBoundNamed(serviceIdentifier, named) {
|
|
337
206
|
return this.isBoundTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
|
|
207
|
+
}
|
|
208
|
+
isBoundTagged(serviceIdentifier, key, value) {
|
|
209
|
+
let bound = false;
|
|
341
210
|
if (this._bindingDictionary.hasKey(serviceIdentifier)) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
bound = bindings.some(
|
|
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
|
-
|
|
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
|
-
|
|
355
|
-
|
|
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
|
-
|
|
366
|
-
|
|
233
|
+
}
|
|
234
|
+
createChild(containerOptions) {
|
|
235
|
+
const child = new Container(containerOptions || this.options);
|
|
367
236
|
child.parent = this;
|
|
368
237
|
return child;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
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(
|
|
379
|
-
}
|
|
380
|
-
|
|
243
|
+
this._middleware = middlewares.reduce((prev, curr) => curr(prev), initial);
|
|
244
|
+
}
|
|
245
|
+
applyCustomMetadataReader(metadataReader) {
|
|
381
246
|
this._metadataReader = metadataReader;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
|
|
247
|
+
}
|
|
248
|
+
get(serviceIdentifier) {
|
|
249
|
+
const getArgs = this._getNotAllArgs(serviceIdentifier, false);
|
|
385
250
|
return this._getButThrowIfAsync(getArgs);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
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
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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
|
-
|
|
413
|
-
return
|
|
414
|
-
|
|
415
|
-
|
|
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
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
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
|
-
|
|
449
|
-
return
|
|
450
|
-
|
|
451
|
-
|
|
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
|
-
|
|
297
|
+
const resolved = this.get(constructorFunction);
|
|
461
298
|
if (!isBound) {
|
|
462
299
|
this.unbind(constructorFunction);
|
|
463
300
|
}
|
|
464
301
|
return resolved;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
var _a, _b;
|
|
302
|
+
}
|
|
303
|
+
_preDestroy(constructor, instance) {
|
|
468
304
|
if (constructor !== undefined &&
|
|
469
305
|
Reflect.hasMetadata(METADATA_KEY.PRE_DESTROY, constructor)) {
|
|
470
|
-
|
|
471
|
-
return
|
|
306
|
+
const data = Reflect.getMetadata(METADATA_KEY.PRE_DESTROY, constructor);
|
|
307
|
+
return instance[data.value]?.();
|
|
472
308
|
}
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
|
|
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
|
-
|
|
480
|
-
return this._bindingDictionary.removeByCondition(
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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
|
-
|
|
354
|
+
const result = deactivation.value(instance);
|
|
537
355
|
if ((0, async_1.isPromise)(result)) {
|
|
538
|
-
return result.then(
|
|
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
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
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
|
-
|
|
571
|
-
|
|
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
|
-
|
|
578
|
-
|
|
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
|
-
|
|
588
|
-
return
|
|
589
|
-
return _this.isBound(serviceIdentifier);
|
|
590
|
-
};
|
|
380
|
+
const getIsboundFunction = () => (serviceIdentifier) => {
|
|
381
|
+
return this.isBound(serviceIdentifier);
|
|
591
382
|
};
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
return
|
|
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
|
-
|
|
600
|
-
|
|
601
|
-
|
|
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
|
-
|
|
606
|
-
|
|
607
|
-
|
|
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
|
|
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
|
-
|
|
629
|
-
|
|
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
|
-
|
|
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
|
-
|
|
640
|
-
|
|
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
|
-
|
|
647
|
-
|
|
440
|
+
}
|
|
441
|
+
_getAllArgs(serviceIdentifier) {
|
|
442
|
+
const getAllArgs = {
|
|
648
443
|
avoidConstraints: true,
|
|
649
444
|
isMultiInject: true,
|
|
650
|
-
serviceIdentifier
|
|
445
|
+
serviceIdentifier,
|
|
651
446
|
};
|
|
652
447
|
return getAllArgs;
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
|
|
448
|
+
}
|
|
449
|
+
_getNotAllArgs(serviceIdentifier, isMultiInject, key, value) {
|
|
450
|
+
const getNotAllArgs = {
|
|
656
451
|
avoidConstraints: false,
|
|
657
|
-
isMultiInject
|
|
658
|
-
key
|
|
659
|
-
serviceIdentifier
|
|
660
|
-
value
|
|
452
|
+
isMultiInject,
|
|
453
|
+
key,
|
|
454
|
+
serviceIdentifier,
|
|
455
|
+
value,
|
|
661
456
|
};
|
|
662
457
|
return getNotAllArgs;
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
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
|
-
|
|
463
|
+
const result = (0, resolver_1.resolve)(context);
|
|
670
464
|
return result;
|
|
671
465
|
};
|
|
672
|
-
}
|
|
673
|
-
|
|
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(
|
|
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
|
-
|
|
686
|
-
for (
|
|
687
|
-
|
|
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
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
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
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
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(
|
|
508
|
+
throw new Error(`${ERROR_MSGS.CANNOT_UNBIND} ${(0, serialization_1.getServiceIdentifierAsString)(serviceIdentifier)}`);
|
|
742
509
|
}
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
var _this = this;
|
|
510
|
+
}
|
|
511
|
+
_bindingDeactivationAndPreDestroy(binding, instance, constructor) {
|
|
746
512
|
if (typeof binding.onDeactivation === 'function') {
|
|
747
|
-
|
|
513
|
+
const result = binding.onDeactivation(instance);
|
|
748
514
|
if ((0, async_1.isPromise)(result)) {
|
|
749
|
-
return result.then(
|
|
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
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
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;
|