Skip to content

Commit cb44ae5

Browse files
ensure that we only match non-keyed if ServiceLookupMode is NullKey
1 parent 61c9c5a commit cb44ae5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Ninject.Web.AspNetCore/Planning/ParameterTargetWithKeyedSupport.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ protected override Func<IBindingMetadata, bool> ReadConstraintFromTarget()
3434
#if NET8_0_OR_GREATER
3535
var keyedattributes = GetCustomAttributes(typeof (FromKeyedServicesAttribute), true) as FromKeyedServicesAttribute[];
3636
var baseFunc = base.ReadConstraintFromTarget();
37-
if (keyedattributes == null || keyedattributes.Length == 0)
37+
if (keyedattributes == null || keyedattributes.Length == 0
38+
#if NET10_0_OR_GREATER
39+
|| (keyedattributes[0].LookupMode == ServiceKeyLookupMode.NullKey)
40+
#endif
41+
)
3842
{
3943
return baseFunc;
4044
}
@@ -51,6 +55,12 @@ protected override Func<IBindingMetadata, bool> ReadConstraintFromTarget()
5155
{
5256
result = result && metadata.DoesMetadataMatchServiceKey(keyedattributes[0].Key, true);
5357
}
58+
else
59+
{
60+
// we can't match bindings here which don't have a servicekey. If FromKeyServiceAttribute is present
61+
// the match fails if no servicekey available.
62+
result = false;
63+
}
5464

5565
return result;
5666
};

0 commit comments

Comments
 (0)