The SomeRepository type is not being return by GetPublicClassesFromApplicationAssembly. I want all types of classes extending IRepository to be returned. Can anyone see the problem?
private Type[] GetPublicClassesFromApplicationAssembly()
{
return typeof (SomeRepository).Assembly.GetExportedTypes()
.Where(t => t.IsClass)
.Where(t => t.IsAbstract == false)
.Where(r => r.IsAssignableFrom(typeof(IRepository<>)))
.OrderBy(t => t.Name)
.ToArray();
}
public class SomeRepository : IRepository<SomeDomainClass> {}
public interface IRepository<T> where T : PrimaryKeyBase {}
public class SomeDomainClass: PrimaryKeyBase {}
SomeRepositoryis not assignable fromIRepository<>, which is not a “real” type; it’s assignable fromIRepository<SomeDomainClass>. You need to useGetInterfaceinstead ofIsAssignableFrom: