-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathExposedRootsViaRootArgScenario.cs
62 lines (55 loc) · 1.83 KB
/
ExposedRootsViaRootArgScenario.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=203
$d=Exposed roots via root arg
$h=Composition roots from other assemblies or projects can be used as a source of bindings passed through root arguments. When you add a binding to a composition from another assembly or project, the roots of the composition with the `RootKind.Exposed` type will be used in the bindings automatically. For example, in some assembly a composition is defined as:
$h=```c#
$h=public partial class CompositionInOtherProject
$h={
$h= private static void Setup() =>
$h= DI.Setup()
$h= .Bind().As(Lifetime.Singleton).To<MyDependency>()
$h= .Bind().To<MyService>()
$h= .Root<IMyService>("MyService", kind: RootKinds.Exposed);
$h=}
$h=```
*/
// ReSharper disable ClassNeverInstantiated.Local
// ReSharper disable CheckNamespace
// ReSharper disable UnusedParameter.Local
// ReSharper disable RedundantAssignment
// ReSharper disable ArrangeTypeModifiers
// ReSharper disable PartialTypeWithSinglePart
#pragma warning disable CS9113 // Parameter is unread.
namespace Pure.DI.UsageTests.Advanced.ExposedRootsViaRootArgScenario;
using OtherAssembly;
using Pure.DI;
using Xunit;
// {
//# using Pure.DI;
//# using OtherAssembly;
// }
public class Scenario
{
[Fact]
public void Run()
{
// {
DI.Setup(nameof(Composition))
.Hint(Hint.Resolve, "Off")
// Binds to exposed composition roots from other project
.RootArg<CompositionInOtherProject>("baseComposition")
.Root<Program>("GetProgram");
var baseComposition = new CompositionInOtherProject();
var composition = new Composition();
var program = composition.GetProgram(baseComposition);
program.DoSomething();
// }
}
}
// {
partial class Program(IMyService myService)
{
public void DoSomething() => myService.DoSomething();
}
// }