forked from dadhi/DryIoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImportExternalTests.CUT.cs
97 lines (79 loc) · 2.15 KB
/
ImportExternalTests.CUT.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.ComponentModel.Composition;
using DryIocAttributes;
namespace DryIoc.MefAttributedModel.UnitTests.CUT
{
[Export, TransientReuse]
public class NativeUser
{
public IForeignTool Tool { get; set; }
public NativeUser([ImportExternal(typeof(ForeignTool), contractType: typeof(ForeignTool)), TransientReuse] IForeignTool tool)
{
Tool = tool;
}
}
public interface IForeignTool
{
}
public class ForeignTool : IForeignTool
{
}
[Export]
public class HomeUser
{
public ExternalTool Tool { get; set; }
public HomeUser([ImportExternal(constructorSignature: new[] { typeof(string) })] Func<string, ExternalTool> getTool)
{
Tool = getTool("blah");
}
}
public class ExternalTool
{
public string Message { get; set; }
public ExternalTool()
{
}
public ExternalTool(string message)
{
Message = message;
}
}
[ExportMany]
public class ServiceWithFieldAndProperty
{
[ImportExternal(typeof(AnotherService), contractKey: "blah")]
public IService Field;
[ImportExternal(ImplementationType = typeof(AnotherService), ContractKey = "blah")]
public IService Property { get; set; }
}
[Export]
public class OneDependsOnExternalTool
{
public readonly ExternalTool Tool;
public OneDependsOnExternalTool([ImportExternal(constructorSignature: new Type[0], contractKey: 13)]ExternalTool tool)
{
Tool = tool;
}
}
[Export]
public class OtherDependsOnExternalTool
{
public readonly ExternalTool Tool;
public OtherDependsOnExternalTool([ImportEx(13)]ExternalTool tool)
{
Tool = tool;
}
}
[ExportMany]
public class WithUnregisteredExternalDependency
{
public ExternalTool Tool { get; set; }
public WithUnregisteredExternalDependency([SomeOther]ExternalTool tool)
{
Tool = tool;
}
}
public class SomeOtherAttribute : Attribute
{
}
}