-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathValueTaskScenario.cs
64 lines (53 loc) · 1.1 KB
/
ValueTaskScenario.cs
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
/*
$v=true
$p=3
$d=ValueTask
*/
// ReSharper disable ClassNeverInstantiated.Local
// ReSharper disable CheckNamespace
// ReSharper disable ArrangeTypeModifiers
namespace Pure.DI.UsageTests.BCL.ValueTaskScenario;
using Xunit;
// {
//# using Pure.DI;
// }
public class Scenario
{
[Fact]
public async Task Run()
{
// {
DI.Setup(nameof(Composition))
.Bind<IDependency>().To<Dependency>()
.Bind<IService>().To<Service>()
// Composition root
.Root<IService>("Root");
var composition = new Composition();
var service = composition.Root;
await service.RunAsync();
// }
composition.SaveClassDiagram();
}
}
// {
interface IDependency
{
ValueTask DoSomething();
}
class Dependency : IDependency
{
public ValueTask DoSomething() => ValueTask.CompletedTask;
}
interface IService
{
ValueTask RunAsync();
}
class Service(ValueTask<IDependency> dependencyTask) : IService
{
public async ValueTask RunAsync()
{
var dependency = await dependencyTask;
await dependency.DoSomething();
}
}
// }