-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.mjs
40 lines (33 loc) · 819 Bytes
/
test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { inject, provide, init } from './index.mjs';
const TYPES = {
serviceFoo: Symbol('serviceFoo'),
serviceBar: Symbol('serviceBar'),
serviceBaz: Symbol('serviceBaz'),
};
provide(
TYPES.serviceFoo,
() => new class {
bar = inject(TYPES.serviceBar);
}
);
provide(
TYPES.serviceBar,
() => new class {
foo = inject(TYPES.serviceFoo);
baz = inject(TYPES.serviceBaz);
}
);
provide(
TYPES.serviceBaz,
() => new class { }
);
const ioc = {
serviceFoo: inject(TYPES.serviceFoo),
serviceBar: inject(TYPES.serviceBar),
serviceBaz: inject(TYPES.serviceBaz),
};
init();
console.log(ioc.serviceFoo.bar.foo.bar.foo.bar.baz.name);
console.log(ioc.serviceFoo.bar.name);
console.log(ioc.serviceBar.foo.name);
console.log(ioc.serviceBar.baz.name);