-
Notifications
You must be signed in to change notification settings - Fork 22
/
OverridingBclBindingScenario.cs
62 lines (51 loc) · 1.42 KB
/
OverridingBclBindingScenario.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
/*
$v=true
$p=100
$d=Overriding the BCL binding
$h=At any time, the default binding to the BCL type can be changed to your own:
*/
// ReSharper disable ClassNeverInstantiated.Local
// ReSharper disable CheckNamespace
// ReSharper disable ArrangeTypeModifiers
namespace Pure.DI.UsageTests.BCL.OverridingBclBindingScenario;
using Shouldly;
using Xunit;
// {
interface IDependency;
class AbcDependency : IDependency;
class XyzDependency : IDependency;
interface IService
{
IDependency[] Dependencies { get; }
}
class Service(IDependency[] dependencies) : IService
{
public IDependency[] Dependencies { get; } = dependencies;
}
// }
public class Scenario
{
[Fact]
public void Run()
{
// {
DI.Setup(nameof(Composition))
.Bind<IDependency[]>().To(_ => new IDependency[]
{
new AbcDependency(),
new XyzDependency(),
new AbcDependency()
})
.Bind<IService>().To<Service>()
// Composition root
.Root<IService>("Root");
var composition = new Composition();
var service = composition.Root;
service.Dependencies.Length.ShouldBe(3);
service.Dependencies[0].ShouldBeOfType<AbcDependency>();
service.Dependencies[1].ShouldBeOfType<XyzDependency>();
service.Dependencies[2].ShouldBeOfType<AbcDependency>();
// }
composition.SaveClassDiagram();
}
}