diff --git a/src/Scrutor/ReflectionExtensions.cs b/src/Scrutor/ReflectionExtensions.cs index a477df4e..e8e41edf 100644 --- a/src/Scrutor/ReflectionExtensions.cs +++ b/src/Scrutor/ReflectionExtensions.cs @@ -234,6 +234,11 @@ public static bool HasMatchingGenericArity(this Type interfaceType, Type type) { if (interfaceType.IsGenericType) { + if (!interfaceType.ContainsGenericParameters) + { + return true; + } + var argumentCount = interfaceType.GetGenericArguments().Length; var parameterCount = type.GetGenericArguments().Length; diff --git a/test/Scrutor.Tests/ScanningTests.cs b/test/Scrutor.Tests/ScanningTests.cs index 46f2d7d0..57b623f3 100644 --- a/test/Scrutor.Tests/ScanningTests.cs +++ b/test/Scrutor.Tests/ScanningTests.cs @@ -220,6 +220,19 @@ public void CanRegisterGenericTypes() Assert.Equal(typeof(QueryHandler), service.ImplementationType); } + [Fact] + public void CanRegisterFullyClosedGenericWithDifferentArityThanServiceType() + { + Collection.Scan(scan => scan + .FromTypes(typeof(PartiallyClosedGeneric)) + .AsImplementedInterfaces() + .WithTransientLifetime()); + + var descriptor = Assert.Single(Collection); + + Assert.Equal(typeof(IPartiallyClosedGeneric), descriptor.ServiceType); + } + [Fact] public void CanScanUsingAttributes() {