@@ -13,8 +13,10 @@ public int Run()
13
13
{
14
14
Can_inject_required_properties ( ) ;
15
15
Should_throw_for_unresolved_required_property ( ) ;
16
- Should_skip_required_property_injection_when_using_ctor_with_SetsRequiredProperties ( ) ;
17
- return 3 ;
16
+ Should_skip_required_property_injection_when_using_ctor_which_SetsRequiredProperties ( ) ;
17
+ Works_with_constructor_selector ( ) ;
18
+ Works_with_open_generic_registration_and_constructor_selector_which_SetsRequiredProperties ( ) ;
19
+ return 5 ;
18
20
}
19
21
20
22
[ Test ]
@@ -49,7 +51,7 @@ public void Should_throw_for_unresolved_required_property()
49
51
}
50
52
51
53
[ Test ]
52
- public void Should_skip_required_property_injection_when_using_ctor_with_SetsRequiredProperties ( )
54
+ public void Should_skip_required_property_injection_when_using_ctor_which_SetsRequiredProperties ( )
53
55
{
54
56
var c = new Container ( Rules . Default . With ( propertiesAndFields : PropertiesAndFields . RequiredProperties ( ) ) ) ;
55
57
@@ -64,6 +66,44 @@ public void Should_skip_required_property_injection_when_using_ctor_with_SetsReq
64
66
Assert . NotNull ( x . B ) ;
65
67
}
66
68
69
+ [ Test ]
70
+ public void Works_with_constructor_selector ( )
71
+ {
72
+ var c = new Container (
73
+ Rules . Default . With (
74
+ factoryMethod : FactoryMethod . ConstructorWithResolvableArguments ,
75
+ propertiesAndFields : PropertiesAndFields . RequiredProperties ( ) ) ) ;
76
+
77
+ c . Register < SSS > ( ) ;
78
+
79
+ c . Register < A > ( ) ;
80
+ c . Register < B > ( ) ;
81
+
82
+ var x = c . Resolve < SSS > ( ) ;
83
+
84
+ Assert . NotNull ( x . A ) ;
85
+ Assert . NotNull ( x . B ) ;
86
+ }
87
+
88
+ [ Test ]
89
+ public void Works_with_open_generic_registration_and_constructor_selector_which_SetsRequiredProperties ( )
90
+ {
91
+ var c = new Container (
92
+ Rules . Default . With (
93
+ factoryMethod : FactoryMethod . ConstructorWithResolvableArguments ,
94
+ propertiesAndFields : PropertiesAndFields . RequiredProperties ( ) ) ) ;
95
+
96
+ c . Register ( typeof ( SS < > ) ) ;
97
+ c . Register ( typeof ( B < > ) ) ;
98
+ c . Register < A > ( ) ;
99
+
100
+ var x = c . Resolve < SS < A > > ( ) ;
101
+
102
+ Assert . Null ( x . A ) ;
103
+ Assert . NotNull ( x . B ) ;
104
+ Assert . IsInstanceOf < A > ( x . B . A ) ;
105
+ }
106
+
67
107
public class A { }
68
108
public class B { }
69
109
public class C { }
@@ -90,6 +130,32 @@ public class SS
90
130
[ SetsRequiredMembers ]
91
131
public SS ( B b ) => B = b ;
92
132
}
133
+
134
+ public class SSS
135
+ {
136
+ public required A A { get ; init ; }
137
+ public B B { get ; private set ; }
138
+
139
+ public SSS ( B b ) => B = b ;
140
+
141
+ public SSS ( ) => B = null ;
142
+ }
143
+
144
+ public class B < T >
145
+ {
146
+ public required T A { get ; init ; }
147
+ }
148
+
149
+ public class SS < T >
150
+ {
151
+ public required A A { get ; init ; }
152
+ public B < T > B { get ; private set ; }
153
+
154
+ [ SetsRequiredMembers ]
155
+ public SS ( B < T > b ) => B = b ;
156
+
157
+ public SS ( ) => B = null ;
158
+ }
93
159
#endif
94
160
}
95
161
}
0 commit comments