File tree 2 files changed +30
-3
lines changed
2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ namespace DryIoc
39
39
using System.Collections;
40
40
using System.Collections.Generic;
41
41
using System.Diagnostics; // for StackTrace
42
- using System.Diagnostics.CodeAnalysis; // for SuppressMessage
42
+ using System.Diagnostics.CodeAnalysis; // for SuppressMessage, SetsRequiredPropertiesAttribute
43
43
using System.Linq;
44
44
using System.Reflection;
45
45
using System.Reflection.Emit;
Original file line number Diff line number Diff line change 1
- using NUnit . Framework ;
1
+ using System . Diagnostics . CodeAnalysis ;
2
+ using NUnit . Framework ;
2
3
3
4
namespace DryIoc . UnitTests
4
5
{
@@ -12,7 +13,8 @@ public int Run()
12
13
{
13
14
Can_inject_required_properties ( ) ;
14
15
Should_throw_for_unresolved_required_property ( ) ;
15
- return 2 ;
16
+ Should_skip_required_property_injection_when_using_ctor_with_SetsRequiredProperties ( ) ;
17
+ return 3 ;
16
18
}
17
19
18
20
[ Test ]
@@ -46,6 +48,22 @@ public void Should_throw_for_unresolved_required_property()
46
48
Assert . AreEqual ( Error . NameOf ( Error . UnableToResolveUnknownService ) , ex . ErrorName ) ;
47
49
}
48
50
51
+ [ Test ]
52
+ public void Should_skip_required_property_injection_when_using_ctor_with_SetsRequiredProperties ( )
53
+ {
54
+ var c = new Container ( Rules . Default . With ( propertiesAndFields : PropertiesAndFields . RequiredProperties ( ) ) ) ;
55
+
56
+ c . Register < SS > ( ) ;
57
+
58
+ c . Register < A > ( ) ;
59
+ c . Register < B > ( ) ;
60
+
61
+ var x = c . Resolve < SS > ( ) ;
62
+
63
+ Assert . Null ( x . A ) ;
64
+ Assert . NotNull ( x . B ) ;
65
+ }
66
+
49
67
public class A { }
50
68
public class B { }
51
69
public class C { }
@@ -63,6 +81,15 @@ public class BS
63
81
{
64
82
public required D D { protected get ; set ; }
65
83
}
84
+
85
+ public class SS
86
+ {
87
+ public required A A { get ; init ; }
88
+ public B B { get ; private set ; }
89
+
90
+ [ SetsRequiredMembers ]
91
+ public SS ( B b ) => B = b ;
92
+ }
66
93
#endif
67
94
}
68
95
}
You can’t perform that action at this time.
0 commit comments