Skip to content

Commit

Permalink
Merge pull request #2 from autofac/develop
Browse files Browse the repository at this point in the history
Update code
  • Loading branch information
RaymondHuy authored Jul 30, 2019
2 parents 9f51225 + 3595bf9 commit 9b784b6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Autofac/Util/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ private static bool ParameterCompatibleWithTypeConstraint(Type parameter, Type c
{
var paramArg = baseType.GenericTypeArguments[i];
var constraintArg = constraint.GenericTypeArguments[i];
var constraintArgIsGeneric = constraintArg.GetTypeInfo().IsGenericType;

allGenericParametersMatch &= paramArg.IsClosedTypeOf(constraintArg.GetGenericTypeDefinition());
allGenericParametersMatch &= paramArg.IsClosedTypeOf(constraintArgIsGeneric ? constraintArg.GetGenericTypeDefinition() : constraintArg);
}
}

Expand Down
29 changes: 29 additions & 0 deletions test/Autofac.Test/Features/OpenGenerics/ComplexGenericsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@ public void WhenTheSameTypeAppearsMultipleTimesInTheImplementationMappingItMustA
container.Resolve<IDouble<decimal, INested<IDouble<string, int>>>>());
}

[Fact]
public void TestSelfReferentialGeneric()
{
var cb = new ContainerBuilder();
cb.RegisterGeneric(typeof(SelfReferenceConsumer<>)).As(typeof(IBaseGeneric<>));
var container = cb.Build();

var instance = container.Resolve<IBaseGeneric<DerivedSelfReferencing>>();
}

public class C<T> : I1<T>, I2<T>
{
}
Expand Down Expand Up @@ -410,5 +420,24 @@ public class SameTypes<TA, TB, TC> : IDouble<INested<TA>, INested<IDouble<TB, TC
public class Wrapper<T>
{
}

public interface IBaseGeneric<TDerived>
where TDerived : BaseGenericImplementation<TDerived>, new()
{
}

public class SelfReferenceConsumer<TSource> : IBaseGeneric<TSource>
where TSource : BaseGenericImplementation<TSource>, new()
{
}

public abstract class BaseGenericImplementation<TDerived>
{
}

public class DerivedSelfReferencing : BaseGenericImplementation<DerivedSelfReferencing>
{
}

}
}

0 comments on commit 9b784b6

Please sign in to comment.