New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registration of collections of variant types where implementation type is unknown to Simple Injector fails #627

dotnetjunkie opened this Issue Oct 30, 2018 · 1 comment


1 participant

dotnetjunkie commented Oct 30, 2018

The following code should succeed:

public class Base { }
public class Derived : Base { }
public interface IContra<in T> where T : Base { }
public class Impl<T> : IContra<T> where T : Base { }

public void Test()
    // Arrange
    var container = new Container();
    IContra<Base> impl = new Impl<Base>();

    // Act
        Lifestyle.Transient.CreateRegistration<IContra<Base>>(() => impl, container),
        Lifestyle.Transient.CreateRegistration<IContra<Derived>>(() => impl, container)

    var deriveds = container.GetAllInstances<IContra<Derived>>();
    var bases = container.GetAllInstances<IContra<Base>>();
    // Assert
    Assert.AreEqual(2, deriveds.Count(), "Two registrations were made for IContra<Derived>.");
    Assert.AreEqual(0, bases.Count(), "No registrations were made for IContra<Base>.");

However, this code fails on the call to container.Collection.Register<IContra<Derived>>. This is because there is a bug in Types.ServiceIsAssignableFromImplementation. It doesn't correclty handle situations where both the supplied service Type and implementation type are closed-generic versions of the same abstraction.


This comment has been minimized.


dotnetjunkie commented Oct 31, 2018

Seems that the Collection.Append overloads are affected as well.

@dotnetjunkie dotnetjunkie changed the title from Registration of collections of variant types where implemention is unknown to Simple Injector fails to Registration of collections of variant types where implementation type is unknown to Simple Injector fails Nov 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment