1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | exports.Bindings = void 0;
|
12 | const IocLookupException_1 = require("../Exceptions/IocLookupException");
|
13 |
|
14 |
|
15 |
|
16 | class Bindings {
|
17 | constructor(container) {
|
18 | this.container = container;
|
19 | |
20 |
|
21 |
|
22 | this.list = new Map();
|
23 | }
|
24 | |
25 |
|
26 |
|
27 | has(namespace) {
|
28 | return this.list.has(namespace);
|
29 | }
|
30 | |
31 |
|
32 |
|
33 | register(binding, callback, singleton) {
|
34 | this.list.set(binding, { callback, singleton });
|
35 | return this;
|
36 | }
|
37 | |
38 |
|
39 |
|
40 | resolve(binding) {
|
41 | const bindingNode = this.list.get(binding);
|
42 | if (!bindingNode) {
|
43 | throw IocLookupException_1.IocLookupException.lookupFailed(binding);
|
44 | }
|
45 | let resolvedValue;
|
46 | if (bindingNode.singleton) {
|
47 | bindingNode.cachedValue = bindingNode.cachedValue ?? bindingNode.callback(this.container);
|
48 | resolvedValue = bindingNode.cachedValue;
|
49 | }
|
50 | else {
|
51 | resolvedValue = bindingNode.callback(this.container);
|
52 | }
|
53 | return resolvedValue;
|
54 | }
|
55 | }
|
56 | exports.Bindings = Bindings;
|