@@ -52,9 +52,20 @@ private class HandlerWithUnrelatedTypeParam<TParam>
5252 {
5353 }
5454
55+ /// <summary>
56+ /// Handler implementing several non-mappable interfaces before the single mappable one,
57+ /// to ensure ordering robustness beyond the two-interface case.
58+ /// </summary>
59+ private class HandlerMappableLast < TParam >
60+ : IHandler < IRequest > , IHandler < string > , IHandler < IRequest < TParam > >
61+ {
62+ }
63+
5564 [ Fact ]
5665 public void MappableFirstHandlerIsResolvable ( )
5766 {
67+ // #1464 control case: when the mappable interface (IHandler<IRequest<TParam>>)
68+ // appears first, binding worked before the fix and must continue to work.
5869 var builder = new ContainerBuilder ( ) ;
5970 builder
6071 . RegisterGeneric ( typeof ( HandlerMappableFirst < > ) )
@@ -86,6 +97,40 @@ public void NonMappableFirstHandlerIsResolvable()
8697 Assert . IsType < HandlerNonMappableFirst < int > > ( handlers . Single ( ) ) ;
8798 }
8899
100+ [ Fact ]
101+ public void NonMappableFirstHandlerIsResolvableAsSingleService ( )
102+ {
103+ // #1464: the single-service resolution path (TryGetRegistration) goes through
104+ // different ServiceRegistrationInfo logic than the enumerable path, so guard it
105+ // explicitly - a non-mappable interface first must not break a direct resolve.
106+ var builder = new ContainerBuilder ( ) ;
107+ builder
108+ . RegisterGeneric ( typeof ( HandlerNonMappableFirst < > ) )
109+ . As ( typeof ( IHandler < > ) . MakeGenericType ( typeof ( IRequest < > ) ) ) ;
110+
111+ var container = builder . Build ( ) ;
112+
113+ var handler = container . Resolve < IHandler < IRequest < int > > > ( ) ;
114+ Assert . IsType < HandlerNonMappableFirst < int > > ( handler ) ;
115+ }
116+
117+ [ Fact ]
118+ public void MappableInterfaceFoundWhenItIsNotFirstAmongSeveral ( )
119+ {
120+ // #1464: ordering robustness beyond two interfaces - the mappable interface is
121+ // the third one implemented, after two non-mappable ones.
122+ var builder = new ContainerBuilder ( ) ;
123+ builder
124+ . RegisterGeneric ( typeof ( HandlerMappableLast < > ) )
125+ . As ( typeof ( IHandler < > ) . MakeGenericType ( typeof ( IRequest < > ) ) ) ;
126+
127+ var container = builder . Build ( ) ;
128+
129+ var handlers = container . Resolve < IEnumerable < IHandler < IRequest < int > > > > ( ) ;
130+ Assert . Single ( handlers ) ;
131+ Assert . IsType < HandlerMappableLast < int > > ( handlers . Single ( ) ) ;
132+ }
133+
89134 [ Fact ]
90135 public void BothHandlerOrderVariantsAreResolvedFromEnumerable ( )
91136 {
0 commit comments