-
Notifications
You must be signed in to change notification settings - Fork 22
/
ExposedGenericRootsWithArgsScenario.cs
58 lines (52 loc) · 1.84 KB
/
ExposedGenericRootsWithArgsScenario.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
/*
$v=true
$p=211
$d=Exposed generic roots with args
$h=Composition roots from other assemblies or projects can be used as a source of bindings. 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 CompositionWithGenericRootsAndArgsInOtherProject
$h={
$h= private static void Setup() =>
$h= DI.Setup()
$h= .Hint(Hint.Resolve, "Off")
$h= .RootArg<int>("id")
$h= .Bind().As(Lifetime.Singleton).To<MyDependency>()
$h= .Bind().To<MyGenericService<TT>>()
$h= .Root<IMyGenericService<TT>>("GetMyService", kind: RootKinds.Exposed);
$h=}
$h=```
*/
// ReSharper disable ClassNeverInstantiated.Local
// ReSharper disable CheckNamespace
// ReSharper disable UnusedParameter.Local
// ReSharper disable RedundantAssignment
// ReSharper disable ArrangeTypeModifiers
#pragma warning disable CS9113 // Parameter is unread.
namespace Pure.DI.UsageTests.Advanced.ExposedGenericRootsWithArgsScenario;
using Integration;
using Pure.DI;
using Xunit;
// {
class Program(IMyGenericService<int> myService)
{
public void DoSomething(int value) => myService.DoSomething(value);
}
// }
public class Scenario
{
[Fact]
public void Run()
{
// {
DI.Setup(nameof(Composition))
.Hint(Hint.Resolve, "Off")
.RootArg<int>("id")
// Binds to exposed composition roots from other project
.Bind().As(Lifetime.Singleton).To<CompositionWithGenericRootsAndArgsInOtherProject>()
.Root<Program>("GetProgram");
var composition = new Composition();
var program = composition.GetProgram(33);
program.DoSomething(99);
// }
}
}