-
Notifications
You must be signed in to change notification settings - Fork 22
/
LazyScenario.cs
51 lines (41 loc) · 945 Bytes
/
LazyScenario.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
/*
$v=true
$p=3
$d=Lazy
*/
// ReSharper disable ClassNeverInstantiated.Local
// ReSharper disable CheckNamespace
// ReSharper disable ArrangeTypeModifiers
namespace Pure.DI.UsageTests.BCL.LazyScenario;
using Shouldly;
using Xunit;
// {
interface IDependency;
class Dependency : IDependency;
interface IService
{
IDependency Dependency { get; }
}
class Service(Lazy<IDependency> dependency) : IService
{
public IDependency Dependency => dependency.Value;
}
// }
public class Scenario
{
[Fact]
public void 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;
service.Dependency.ShouldBe(service.Dependency);
// }
composition.SaveClassDiagram();
}
}