-
Notifications
You must be signed in to change notification settings - Fork 22
/
AsyncEnumerableScenario.cs
66 lines (54 loc) · 1.66 KB
/
AsyncEnumerableScenario.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
65
66
/*
$v=true
$p=7
$d=Async Enumerable
$h=Specifying `IAsyncEnumerable<T>` as the injection type allows instances of all bindings implementing type `T` to be injected in an asynchronous-lazy manner - the instances will be provided one at a time, in an order corresponding to the sequence of the bindings.
*/
// ReSharper disable ClassNeverInstantiated.Local
// ReSharper disable CheckNamespace
// ReSharper disable ArrangeTypeModifiers
namespace Pure.DI.UsageTests.BCL.AsyncEnumerableScenario;
using Shouldly;
using Xunit;
// {
interface IDependency;
class AbcDependency : IDependency;
class XyzDependency : IDependency;
interface IService
{
Task<IReadOnlyList<IDependency>> GetDependenciesAsync();
}
class Service(IAsyncEnumerable<IDependency> dependencies) : IService
{
public async Task<IReadOnlyList<IDependency>> GetDependenciesAsync()
{
var deps = new List<IDependency>();
await foreach (var dependency in dependencies)
{
deps.Add(dependency);
}
return deps;
}
}
// }
public class Scenario
{
[Fact]
public async Task Run()
{
// {
DI.Setup(nameof(Composition))
.Bind<IDependency>().To<AbcDependency>()
.Bind<IDependency>(2).To<XyzDependency>()
.Bind<IService>().To<Service>()
// Composition root
.Root<IService>("Root");
var composition = new Composition();
var service = composition.Root;
var dependencies = await service.GetDependenciesAsync();
dependencies[0].ShouldBeOfType<AbcDependency>();
dependencies[1].ShouldBeOfType<XyzDependency>();
// }
composition.SaveClassDiagram();
}
}