Skip to content

Commit

Permalink
Test for #1315: Ensure it works multiple inheritance levels deep.
Browse files Browse the repository at this point in the history
  • Loading branch information
tillig committed Mar 18, 2022
1 parent 043253f commit 68f6d8f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/Autofac.Specification.Test/Registration/OpenGenericTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ public void ResolveClassWithRenamedTypeArguments()
Assert.IsType<DerivedRepository<int, string>>(resolved);
}

// Issue #1315: Class services fail to resolve if the names on the type
// arguments are changed. We should be able to handle a deep inheritance chain.
[Fact]
public void ResolveClassTwoLevelsDownWithRenamedTypeArguments()
{
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterGeneric(typeof(TwoLevelsDerivedRepository<,>)).As(typeof(BaseRepository<,>));

var container = containerBuilder.Build();
var resolved = container.Resolve<BaseRepository<string, int>>();
Assert.IsType<TwoLevelsDerivedRepository<int, string>>(resolved);
}

private class SelfComponent<T> : IImplementedInterface<T>
{
}
Expand All @@ -68,4 +81,8 @@ private class BaseRepository<T1, T2>
private class DerivedRepository<TSecond, TFirst> : BaseRepository<TFirst, TSecond>
{
}

private class TwoLevelsDerivedRepository<TA, TB> : DerivedRepository<TA, TB>
{
}
}

0 comments on commit 68f6d8f

Please sign in to comment.