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