-
Notifications
You must be signed in to change notification settings - Fork 22
/
AutoBindingsScenario.cs
48 lines (40 loc) · 1.35 KB
/
AutoBindingsScenario.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
/*
$v=true
$p=0
$d=Auto-bindings
$h=Injection of non-abstract types is possible without any additional effort.
$f=> [!WARNING]
$f=> But this approach cannot be recommended if you follow the dependency inversion principle and want your types to depend only on abstractions.
$f=
$f=It is better to inject abstract dependencies, for example, in the form of interfaces. Use bindings to map abstract types to their implementations as in almost all [other examples](injections-of-abstractions.md).
*/
// ReSharper disable CheckNamespace
// ReSharper disable ArrangeTypeModifiers
// ReSharper disable UnusedVariable
// ReSharper disable UnusedMember.Local
// ReSharper disable ArrangeTypeMemberModifiers
#pragma warning disable CS9113 // Parameter is unread.
namespace Pure.DI.UsageTests.Basics.AutoBindingsScenario;
using Xunit;
// {
class Dependency;
class Service(Dependency dependency);
// }
public class Scenario
{
[Fact]
public void Run()
{
// Resolve = Off
// {
// Specifies to create a partial class with name "Composition"
DI.Setup("Composition")
// with the root "MyService"
.Root<Service>("MyService");
var composition = new Composition();
// service = new Service(new Dependency())
var service = composition.MyService;
// }
composition.SaveClassDiagram();
}
}