zcz527 / autofac

Automatically exported from code.google.com/p/autofac
Other
0 stars 0 forks source link

Recursive generic constraint resolution fails in 3.0.1 (was working in 2.6.3.862) #422

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

void Main()
{
    var builder = new ContainerBuilder();
    builder.RegisterGeneric(typeof(DefaultGenericInterfaceImplementation<>)).As(typeof(IGenericInterface<>));
    var container = builder.Build();
    container.Resolve<IGenericInterface<DerivedConstrainedType<UnrelatedConstrainedType>>>().Dump();
}

interface IGenericInterface<T> where T: IConstraint<T>{}

class DefaultGenericInterfaceImplementation<T> : IGenericInterface<T> where T: 
class, IConstraint<T>{}

interface IConstraint<in T> where T:IConstraint<T> {}

interface IUnrelatedConstraint {}

abstract class BaseConstrainedType : IConstraint<BaseConstrainedType>{}

class DerivedConstrainedType<UnrelatedT> : BaseConstrainedType where 
UnrelatedT: IUnrelatedConstraint {}

class UnrelatedConstrainedType : IUnrelatedConstraint{}

What is the expected output? What do you see instead?

Works just fine in 2.6.3.862, in 3.0.1 gives the following error:

GenericArguments[0], 'UserQuery+UnrelatedConstrainedType', on 
'UserQuery+IConstraint`1[T]' violates the constraint of type 'T'.

What version of Autofac are you using? On what version of .NET/Silverlight?

3.0.1

Please provide any additional information below.

Original issue reported on code.google.com by jonas.ch...@nexthink.com on 4 Apr 2013 at 2:57

GoogleCodeExporter commented 8 years ago

Original comment by travis.illig on 4 Apr 2013 at 2:58

GoogleCodeExporter commented 8 years ago
This appears to have been fixed as a byproduct of fixing issue 421 (the root 
cause of the two issues was the same).

The fix for issue 421 has been released on NuGet in Autofac 3.0.2. If it's 
still not working after update, let us know.

Original comment by travis.illig on 9 Apr 2013 at 11:04