-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
resolver.unit.ts
830 lines (698 loc) · 22.5 KB
/
resolver.unit.ts
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
// Node module: @loopback/context
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
import {expect} from '@loopback/testlab';
import {
BindingAddress,
BindingScope,
Context,
Getter,
inject,
Injection,
instantiateClass,
invokeMethod,
Provider,
ResolutionSession,
} from '../..';
describe('constructor injection', () => {
let ctx: Context;
before(function () {
ctx = new Context();
ctx.bind('foo').to('FOO');
ctx.bind('bar').to('BAR');
});
it('resolves constructor arguments', () => {
class TestClass {
constructor(@inject('foo') public foo: string) {}
}
const t = instantiateClass(TestClass, ctx) as TestClass;
expect(t.foo).to.eql('FOO');
});
it('allows non-injected arguments in constructor', () => {
class TestClass {
constructor(
@inject('foo') public foo: string,
public nonInjectedArg: string,
) {}
}
const theNonInjectedArg = 'BAZ';
const test = instantiateClass(TestClass, ctx, undefined, [
theNonInjectedArg,
]) as TestClass;
expect(test.foo).to.eql('FOO');
expect(test.nonInjectedArg).to.eql('BAZ');
});
it('can report error for missing binding key', () => {
expect(() => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class TestClass {
constructor(@inject('', {x: 'bar'}) public fooBar: string) {}
}
}).to.throw(
/A non-empty binding selector or resolve function is required for @inject/,
);
});
it('allows optional constructor injection', () => {
class TestClass {
constructor(
@inject('optional-binding-key', {optional: true})
public fooBar: string | undefined,
) {}
}
const test = instantiateClass(TestClass, ctx) as TestClass;
expect(test.fooBar).to.be.undefined();
});
it('allows optional constructor injection with default value', () => {
class TestClass {
constructor(
@inject('optional-binding-key', {optional: true})
public fooBar: string = 'fooBar',
) {}
}
const test = instantiateClass(TestClass, ctx) as TestClass;
expect(test.fooBar).to.be.eql('fooBar');
});
it('allows optional property injection with default value', () => {
class TestClass {
@inject('optional-binding-key', {optional: true})
public fooBar = 'fooBar';
}
const test = instantiateClass(TestClass, ctx) as TestClass;
expect(test.fooBar).to.be.eql('fooBar');
});
it('resolves constructor arguments with custom resolve function', () => {
class TestClass {
constructor(
@inject('foo', {x: 'bar'}, (c: Context, injection: Injection) => {
const barKey = injection.metadata.x;
const b = c.getSync(barKey);
const f = c.getSync(injection.bindingSelector as BindingAddress);
return f + ':' + b;
})
public fooBar: string,
) {}
}
const t = instantiateClass(TestClass, ctx) as TestClass;
expect(t.fooBar).to.eql('FOO:BAR');
});
it('resolves constructor arguments with custom resolve function and no binding key', () => {
class TestClass {
constructor(
@inject('', {x: 'bar'}, (c: Context, injection: Injection) => {
const barKey = injection.metadata.x;
const b = c.getSync(barKey);
return 'foo' + ':' + b;
})
public fooBar: string,
) {}
}
const t = instantiateClass(TestClass, ctx) as TestClass;
expect(t.fooBar).to.eql('foo:BAR');
});
it('resolves constructor arguments with custom decorator', () => {
class TestClass {
constructor(@customDecorator({x: 'bar'}) public fooBar: string) {}
}
const t = instantiateClass(TestClass, ctx) as TestClass;
expect(t.fooBar).to.eql('FOO:BAR');
});
it('reports circular dependencies of two bindings', () => {
const context = new Context();
interface XInterface {}
interface YInterface {}
class XClass implements XInterface {
@inject('y')
public y: YInterface;
}
class YClass implements YInterface {
@inject('x')
public x: XInterface;
}
context.bind('x').toClass(XClass);
context.bind('y').toClass(YClass);
expect(() => context.getSync('x')).to.throw(
'Circular dependency detected: x --> @XClass.prototype.y ' +
'--> y --> @YClass.prototype.x --> x',
);
expect(() => context.getSync('y')).to.throw(
'Circular dependency detected: y --> @YClass.prototype.x ' +
'--> x --> @XClass.prototype.y --> y',
);
});
it('reports circular dependencies of three bindings', () => {
const context = new Context();
// Declare interfaces so that they can be used for typing
interface XInterface {}
interface YInterface {}
interface ZInterface {}
class XClass {
constructor(@inject('y') public y: YInterface) {}
}
class YClass {
constructor(@inject('z') public z: ZInterface) {}
}
class ZClass {
constructor(@inject('x') public x: XInterface) {}
}
context.bind('x').toClass(XClass);
context.bind('y').toClass(YClass);
context.bind('z').toClass(ZClass);
expect(() => context.getSync('x')).to.throw(
'Circular dependency detected: x --> @XClass.constructor[0] --> y ' +
'--> @YClass.constructor[0] --> z --> @ZClass.constructor[0] --> x',
);
expect(() => context.getSync('y')).to.throw(
'Circular dependency detected: y --> @YClass.constructor[0] --> z ' +
'--> @ZClass.constructor[0] --> x --> @XClass.constructor[0] --> y',
);
expect(() => context.getSync('z')).to.throw(
'Circular dependency detected: z --> @ZClass.constructor[0] --> x ' +
'--> @XClass.constructor[0] --> y --> @YClass.constructor[0] --> z',
);
});
it('will not report circular dependencies if a binding is injected twice', () => {
const context = new Context();
class XClass {}
class YClass {
constructor(
@inject('x') public a: XClass,
@inject('x') public b: XClass,
) {}
}
context.bind('x').toClass(XClass);
context.bind('y').toClass(YClass);
const y: YClass = context.getSync('y');
expect(y.a).to.be.instanceof(XClass);
expect(y.b).to.be.instanceof(XClass);
});
it('tracks path of bindings', () => {
const context = new Context();
let bindingPath = '';
let resolutionPath = '';
class ZClass {
@inject(
'p',
{},
// Set up a custom resolve() to access information from the session
(c: Context, injection: Injection, session: ResolutionSession) => {
bindingPath = session.getBindingPath();
resolutionPath = session.getResolutionPath();
},
)
myProp: string;
}
class YClass {
constructor(@inject('z') public z: ZClass) {}
}
class XClass {
constructor(@inject('y') public y: YClass) {}
}
context.bind('x').toClass(XClass);
context.bind('y').toClass(YClass);
context.bind('z').toClass(ZClass);
context.getSync('x');
expect(bindingPath).to.eql('x --> y --> z');
expect(resolutionPath).to.eql(
'x --> @XClass.constructor[0] --> y --> @YClass.constructor[0]' +
' --> z --> @ZClass.prototype.myProp',
);
});
it('tracks path of bindings for @inject.getter', async () => {
const context = new Context();
let bindingPath = '';
let resolutionPath = '';
let decorators: (string | undefined)[] = [];
class ZClass {
@inject(
'p',
{},
// Set up a custom resolve() to access information from the session
(c: Context, injection: Injection, session: ResolutionSession) => {
bindingPath = session.getBindingPath();
resolutionPath = session.getResolutionPath();
decorators = session.injectionStack.map(i => i.metadata.decorator);
},
)
myProp: string;
}
class YClass {
constructor(@inject.getter('z') public z: Getter<ZClass>) {}
}
class XClass {
constructor(@inject('y') public y: YClass) {}
}
context.bind('x').toClass(XClass);
context.bind('y').toClass(YClass);
context.bind('z').toClass(ZClass);
const x: XClass = context.getSync('x');
await x.y.z();
expect(bindingPath).to.eql('x --> y --> z');
expect(resolutionPath).to.eql(
'x --> @XClass.constructor[0] --> y --> @YClass.constructor[0]' +
' --> z --> @ZClass.prototype.myProp',
);
expect(decorators).to.eql(['@inject', '@inject.getter', '@inject']);
});
it('tracks path of injections', () => {
const context = new Context();
let injectionPath = '';
class ZClass {
@inject(
'p',
{},
// Set up a custom resolve() to access information from the session
(c: Context, injection: Injection, session: ResolutionSession) => {
injectionPath = session.getInjectionPath();
},
)
myProp: string;
}
class YClass {
constructor(@inject('z') public z: ZClass) {}
}
class XClass {
constructor(@inject('y') public y: YClass) {}
}
context.bind('x').toClass(XClass);
context.bind('y').toClass(YClass);
context.bind('z').toClass(ZClass);
context.getSync('x');
expect(injectionPath).to.eql(
'XClass.constructor[0] --> YClass.constructor[0] --> ZClass.prototype.myProp',
);
});
});
describe('async constructor injection', () => {
let ctx: Context;
before(function () {
ctx = new Context();
ctx.bind('foo').toDynamicValue(() => Promise.resolve('FOO'));
ctx.bind('bar').toDynamicValue(() => Promise.resolve('BAR'));
});
it('resolves constructor arguments', async () => {
class TestClass {
constructor(@inject('foo') public foo: string) {}
}
const t = await instantiateClass(TestClass, ctx);
expect(t.foo).to.eql('FOO');
});
it('resolves constructor arguments with custom async decorator', async () => {
class TestClass {
constructor(@customAsyncDecorator({x: 'bar'}) public fooBar: string) {}
}
const t = await instantiateClass(TestClass, ctx);
expect(t.fooBar).to.eql('FOO:BAR');
});
});
describe('property injection', () => {
let ctx: Context;
before(function () {
ctx = new Context();
ctx.bind('foo').to('FOO');
ctx.bind('bar').to('BAR');
});
it('resolves injected properties', () => {
class TestClass {
@inject('foo')
foo: string;
}
const t = instantiateClass(TestClass, ctx) as TestClass;
expect(t.foo).to.eql('FOO');
});
it('can report error for missing binding key', () => {
expect(() => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class TestClass {
@inject('', {x: 'bar'})
public fooBar: string;
}
}).to.throw(
/A non-empty binding selector or resolve function is required for @inject/,
);
});
it('resolves injected properties with custom resolve function', () => {
class TestClass {
@inject('foo', {x: 'bar'}, (c: Context, injection: Injection) => {
const barKey = injection.metadata.x;
const b = c.getSync(barKey);
const f = c.getSync(injection.bindingSelector as BindingAddress);
return f + ':' + b;
})
public fooBar: string;
}
const t = instantiateClass(TestClass, ctx) as TestClass;
expect(t.fooBar).to.eql('FOO:BAR');
});
it('resolves inject properties with custom resolve function and no binding key', () => {
class TestClass {
@inject('', {x: 'bar'}, (c: Context, injection: Injection) => {
const barKey = injection.metadata.x;
const b = c.getSync(barKey);
return 'foo' + ':' + b;
})
public fooBar: string;
}
const t = instantiateClass(TestClass, ctx) as TestClass;
expect(t.fooBar).to.eql('foo:BAR');
});
it('resolves injected properties with custom decorator', () => {
class TestClass {
@customDecorator({x: 'bar'})
public fooBar: string;
}
const t = instantiateClass(TestClass, ctx) as TestClass;
expect(t.fooBar).to.eql('FOO:BAR');
});
});
describe('async property injection', () => {
let ctx: Context;
before(function () {
ctx = new Context();
ctx.bind('foo').toDynamicValue(() => Promise.resolve('FOO'));
ctx.bind('bar').toDynamicValue(() => Promise.resolve('BAR'));
});
it('resolves injected properties', async () => {
class TestClass {
@inject('foo')
foo: string;
}
const t: TestClass = await instantiateClass(TestClass, ctx);
expect(t.foo).to.eql('FOO');
});
it('resolves properties with custom async decorator', async () => {
class TestClass {
@customAsyncDecorator({x: 'bar'})
public fooBar: string;
}
const t = await instantiateClass(TestClass, ctx);
expect(t.fooBar).to.eql('FOO:BAR');
});
});
describe('dependency injection', () => {
let ctx: Context;
before(function () {
ctx = new Context();
ctx.bind('foo').to('FOO');
ctx.bind('bar').to('BAR');
});
it('resolves properties and constructor arguments', () => {
class TestClass {
@inject('bar')
bar: string;
constructor(@inject('foo') public foo: string) {}
}
const t = instantiateClass(TestClass, ctx) as TestClass;
expect(t.foo).to.eql('FOO');
expect(t.bar).to.eql('BAR');
});
});
describe('async dependency injection', () => {
let ctx: Context;
before(function () {
ctx = new Context();
ctx.bind('foo').toDynamicValue(() => Promise.resolve('FOO'));
ctx.bind('bar').toDynamicValue(() => Promise.resolve('BAR'));
});
it('resolves properties and constructor arguments', async () => {
class TestClass {
@inject('bar')
bar: string;
constructor(@inject('foo') public foo: string) {}
}
const t = await instantiateClass(TestClass, ctx);
expect(t.foo).to.eql('FOO');
expect(t.bar).to.eql('BAR');
});
});
describe('async constructor & sync property injection', () => {
let ctx: Context;
before(function () {
ctx = new Context();
ctx.bind('foo').toDynamicValue(() => Promise.resolve('FOO'));
ctx.bind('bar').to('BAR');
});
it('resolves properties and constructor arguments', async () => {
class TestClass {
@inject('bar')
bar: string;
constructor(@inject('foo') public foo: string) {}
}
const t = await instantiateClass(TestClass, ctx);
expect(t.foo).to.eql('FOO');
expect(t.bar).to.eql('BAR');
});
});
describe('async constructor injection with errors', () => {
let ctx: Context;
before(function () {
ctx = new Context();
ctx.bind('foo').toDynamicValue(
() =>
new Promise((resolve, reject) => {
setImmediate(() => {
reject(new Error('foo: error'));
});
}),
);
});
it('resolves properties and constructor arguments', async () => {
class TestClass {
constructor(@inject('foo') public foo: string) {}
}
await expect(instantiateClass(TestClass, ctx)).to.be.rejectedWith(
'foo: error',
);
});
});
describe('async property injection with errors', () => {
let ctx: Context;
before(function () {
ctx = new Context();
ctx.bind('bar').toDynamicValue(async () => {
throw new Error('bar: error');
});
});
it('resolves properties and constructor arguments', async () => {
class TestClass {
@inject('bar')
bar: string;
}
await expect(instantiateClass(TestClass, ctx)).to.be.rejectedWith(
'bar: error',
);
});
});
describe('sync constructor & async property injection', () => {
let ctx: Context;
before(function () {
ctx = new Context();
ctx.bind('foo').to('FOO');
ctx.bind('bar').toDynamicValue(() => Promise.resolve('BAR'));
});
it('resolves properties and constructor arguments', async () => {
class TestClass {
@inject('bar')
bar: string;
constructor(@inject('foo') public foo: string) {}
}
const t = await instantiateClass(TestClass, ctx);
expect(t.foo).to.eql('FOO');
expect(t.bar).to.eql('BAR');
});
});
function customDecorator(def: object) {
return inject('foo', def, (c: Context, injection: Injection) => {
const barKey = injection.metadata.x;
const b = c.getSync(barKey);
const f = c.getSync(injection.bindingSelector as BindingAddress);
return f + ':' + b;
});
}
function customAsyncDecorator(def: object) {
return inject('foo', def, async (c: Context, injection: Injection) => {
const barKey = injection.metadata.x;
const b = await c.get(barKey);
const f = await c.get(injection.bindingSelector as BindingAddress);
return f + ':' + b;
});
}
describe('method injection', () => {
let ctx: Context;
before(function () {
ctx = new Context();
ctx.bind('foo').to('FOO');
ctx.bind('bar').to('BAR');
});
it('resolves method arguments for the prototype', () => {
let savedInstance;
class TestClass {
test(@inject('foo') foo: string) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
savedInstance = this;
return `hello ${foo}`;
}
}
const t = invokeMethod(TestClass.prototype, 'test', ctx);
expect(savedInstance).to.exactly(TestClass.prototype);
expect(t).to.eql('hello FOO');
});
it('resolves method arguments for a given instance', () => {
let savedInstance;
class TestClass {
bar: string;
test(@inject('foo') foo: string) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
savedInstance = this;
this.bar = foo;
return `hello ${foo}`;
}
}
const inst = new TestClass();
const t = invokeMethod(inst, 'test', ctx);
expect(savedInstance).to.exactly(inst);
expect(t).to.eql('hello FOO');
expect(inst.bar).to.eql('FOO');
});
it('reports error for missing binding key', () => {
class TestClass {
test(@inject('key-does-not-exist') fooBar: string) {}
}
expect(() => {
invokeMethod(TestClass.prototype, 'test', ctx);
}).to.throw(/The key .+ is not bound to any value/);
});
it('resolves arguments for a static method', () => {
class TestClass {
static test(@inject('foo') fooBar: string) {
return `Hello, ${fooBar}`;
}
}
const msg = invokeMethod(TestClass, 'test', ctx);
expect(msg).to.eql('Hello, FOO');
});
});
describe('async method injection', () => {
let ctx: Context;
before(function () {
ctx = new Context();
ctx.bind('foo').toDynamicValue(() => Promise.resolve('FOO'));
ctx.bind('bar').toDynamicValue(() => Promise.resolve('BAR'));
});
it('resolves arguments for a prototype method', async () => {
class TestClass {
test(@inject('foo') foo: string) {
return `hello ${foo}`;
}
}
const t = await invokeMethod(TestClass.prototype, 'test', ctx);
expect(t).to.eql('hello FOO');
});
it('resolves arguments for a prototype method with an instance', async () => {
class TestClass {
bar: string;
test(@inject('foo') foo: string) {
this.bar = foo;
return `hello ${foo}`;
}
}
const inst = new TestClass();
const t = await invokeMethod(inst, 'test', ctx);
expect(t).to.eql('hello FOO');
expect(inst.bar).to.eql('FOO');
});
it('resolves arguments for a method that returns a promise', async () => {
let savedInstance;
class TestClass {
bar: string;
test(@inject('foo') foo: string) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
savedInstance = this;
this.bar = foo;
return Promise.resolve(`hello ${foo}`);
}
}
const inst = new TestClass();
const t = await invokeMethod(inst, 'test', ctx);
expect(savedInstance).to.exactly(inst);
expect(t).to.eql('hello FOO');
expect(inst.bar).to.eql('FOO');
});
});
describe('concurrent resolutions', () => {
let asyncCount = 0;
let syncCount = 0;
beforeEach(() => {
asyncCount = 0;
syncCount = 0;
});
it('returns the same value for concurrent resolutions of the same binding - CONTEXT', async () => {
const ctx = new Context('request');
ctx
.bind('asyncValue')
.toProvider(AsyncValueProvider)
.inScope(BindingScope.CONTEXT);
ctx
.bind('syncValue')
.toProvider(SyncValueProvider)
.inScope(BindingScope.CONTEXT);
ctx.bind('AsyncValueUser').toClass(AsyncValueUser);
const user: AsyncValueUser = await ctx.get('AsyncValueUser');
expect(user.asyncValue1).to.eql('async value: 0');
expect(user.asyncValue2).to.eql('async value: 0');
expect(user.syncValue1).to.eql('sync value: 0');
expect(user.syncValue2).to.eql('sync value: 0');
});
it('returns the same value for concurrent resolutions of the same binding - SINGLETON', async () => {
const ctx = new Context('request');
ctx
.bind('asyncValue')
.toProvider(AsyncValueProvider)
.inScope(BindingScope.SINGLETON);
ctx
.bind('syncValue')
.toProvider(SyncValueProvider)
.inScope(BindingScope.SINGLETON);
ctx.bind('AsyncValueUser').toClass(AsyncValueUser);
const user: AsyncValueUser = await ctx.get('AsyncValueUser');
expect(user.asyncValue1).to.eql('async value: 0');
expect(user.asyncValue2).to.eql('async value: 0');
expect(user.syncValue1).to.eql('sync value: 0');
expect(user.syncValue2).to.eql('sync value: 0');
});
it('returns new values for concurrent resolutions of the same binding - TRANSIENT', async () => {
const ctx = new Context('request');
ctx
.bind('asyncValue')
.toProvider(AsyncValueProvider)
.inScope(BindingScope.TRANSIENT);
ctx
.bind('syncValue')
.toProvider(SyncValueProvider)
.inScope(BindingScope.TRANSIENT);
ctx.bind('AsyncValueUser').toClass(AsyncValueUser);
const user: AsyncValueUser = await ctx.get('AsyncValueUser');
expect(user.asyncValue1).to.eql('async value: 0');
expect(user.asyncValue2).to.eql('async value: 1');
expect(user.syncValue1).to.eql('sync value: 0');
expect(user.syncValue2).to.eql('sync value: 1');
});
class AsyncValueProvider implements Provider<string> {
public value() {
return Promise.resolve(`async value: ${asyncCount++}`);
}
}
class SyncValueProvider implements Provider<string> {
public value() {
return `sync value: ${syncCount++}`;
}
}
class AsyncValueUser {
constructor(
@inject('asyncValue') readonly asyncValue1: string,
@inject('asyncValue') readonly asyncValue2: string,
@inject('syncValue') readonly syncValue1: string,
@inject('syncValue') readonly syncValue2: string,
) {}
}
});