Skip to content

Commit

Permalink
PR #1045: Fix #1040 - IsRegistered throws IndexOutOfRangeException fo…
Browse files Browse the repository at this point in the history
…r open generic type
  • Loading branch information
tillig authored Nov 20, 2019
2 parents cf28582 + fb145e4 commit 13ea57d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static bool TryBindServiceType(
out Service[] constructedServices)
{
var swt = service as IServiceWithType;
if (swt != null && swt.ServiceType.GetTypeInfo().IsGenericType)
if (swt != null && swt.ServiceType.GetTypeInfo().IsGenericType && !swt.ServiceType.IsGenericTypeDefinition)
{
var definitionService = (IServiceWithType)swt.ChangeType(swt.ServiceType.GetGenericTypeDefinition());
var serviceGenericArguments = swt.ServiceType.GetTypeInfo().GenericTypeArguments;
Expand Down
11 changes: 11 additions & 0 deletions test/Autofac.Test/Features/OpenGenerics/ComplexGenericsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,17 @@ public void ResolveTypeFromOpenGenericInterfaceTypeParameterIsInterfaceWithConst
var instance = container.Resolve<INested<ISimpleInterface>>();
}

[Fact]
public void CheckGenericTypeIsRegisteredWhenNotSpecifyParameterType()
{
// Issue #1040: IsRegistered throws IndexOutOfRangeException for open generic type
var cb = new ContainerBuilder();
cb.RegisterGeneric(typeof(C<>));
var container = cb.Build();

Assert.False(container.IsRegistered(typeof(C<>)));
}

private class CNestedSimpleInterface : INested<ISimpleInterface>
{
}
Expand Down

0 comments on commit 13ea57d

Please sign in to comment.