1
1
using System ;
2
+ using System . Reflection ;
2
3
using LightInject . SampleLibrary ;
3
4
using Xunit ;
4
5
@@ -10,7 +11,7 @@ public class OpenGenericTests : TestBase
10
11
public void GetInstance_PartiallyClosedGeneric_ReturnsInstance ( )
11
12
{
12
13
var container = CreateContainer ( ) ;
13
- container . Register ( typeof ( IFoo < , > ) , typeof ( HalfClosedFoo < > ) ) ;
14
+ container . Register ( typeof ( IFoo < , > ) , typeof ( HalfClosedFoo < > ) ) ;
14
15
15
16
var instance = container . GetInstance < IFoo < string , int > > ( ) ;
16
17
@@ -43,9 +44,9 @@ public void GetInstance_PartiallyClosedGenericWithDoubleNestedArgument_ReturnsIn
43
44
public void GetInstance_PartialClosedAbstractClass_ReturnsInstance ( )
44
45
{
45
46
var container = CreateContainer ( ) ;
46
- container . Register ( typeof ( Foo < , > ) , typeof ( HalfClosedFooInhertingFromBaseClass < > ) ) ;
47
+ container . Register ( typeof ( Foo < , > ) , typeof ( HalfClosedFooInhertingFromBaseClass < > ) ) ;
47
48
48
- var instance = container . GetInstance < Foo < string , int > > ( ) ;
49
+ var instance = container . GetInstance < Foo < string , int > > ( ) ;
49
50
50
51
Assert . IsType < HalfClosedFooInhertingFromBaseClass < int > > ( instance ) ;
51
52
}
@@ -54,7 +55,7 @@ public void GetInstance_PartialClosedAbstractClass_ReturnsInstance()
54
55
public void GetInstance_ConcreteClass_ReturnsInstance ( )
55
56
{
56
57
var container = CreateContainer ( ) ;
57
- container . Register ( typeof ( Foo < > ) ) ;
58
+ container . Register ( typeof ( Foo < > ) ) ;
58
59
59
60
var instance = container . GetInstance < Foo < int > > ( ) ;
60
61
@@ -84,9 +85,9 @@ public void GetInstance_NamedServiceWithInvalidConstraint_ThrowsException()
84
85
[ Fact ]
85
86
public void GetInstance_NoMatchingOpenGeneric_ThrowsException ( )
86
87
{
87
- var container = CreateContainer ( ) ;
88
+ var container = CreateContainer ( ) ;
88
89
89
- Assert . Throws < InvalidOperationException > ( ( ) => container . GetInstance < IFoo < int > > ( ) ) ;
90
+ Assert . Throws < InvalidOperationException > ( ( ) => container . GetInstance < IFoo < int > > ( ) ) ;
90
91
91
92
}
92
93
@@ -101,5 +102,49 @@ public void GetInstance_NamedOpenGenerics_IgnoresCaseOnServiceNames()
101
102
102
103
Assert . IsType < Foo < int > > ( instance ) ;
103
104
}
105
+
106
+ [ Fact ]
107
+ public void ShouldMapNestGenericArguments ( )
108
+ {
109
+ var container = CreateContainer ( ) ;
110
+
111
+ container . Register ( typeof ( IHandler < > ) , typeof ( Handler < > ) , "Handler" ) ;
112
+ container . Register ( typeof ( IHandler < > ) , typeof ( AnotherHandler < > ) , "AnotherHandler" ) ;
113
+
114
+ var handlerInstance = container . GetInstance < IHandler < Message < string > > > ( ) ;
115
+ Assert . IsType < Handler < string > > ( handlerInstance ) ;
116
+ var anotherHandlerInstance = container . GetInstance < IHandler < AnotherMessage < string > > > ( ) ;
117
+ Assert . IsType < AnotherHandler < string > > ( anotherHandlerInstance ) ;
118
+ }
119
+ }
120
+
121
+ public interface IHandler < TCommand >
122
+ {
123
+ }
124
+
125
+ public class Message < TMessage >
126
+ {
127
+
128
+ }
129
+
130
+ public class AnotherMessage < TAnotherMessage >
131
+ {
132
+
133
+ }
134
+
135
+ public class Handler < TCommand > : IHandler < Message < TCommand > >
136
+ {
137
+ public Handler ( )
138
+ {
139
+
140
+ }
141
+ }
142
+
143
+ public class AnotherHandler < TCommand > : IHandler < AnotherMessage < TCommand > >
144
+ {
145
+ public AnotherHandler ( )
146
+ {
147
+
148
+ }
104
149
}
105
150
}
0 commit comments