title: Assembly scan and register class against interface at dotnet core
body: <p>See the following code:</p>
  
  <pre><code>public interface IUserRepository:IRepository&lt;User&gt;
  {
  
  }
  
  public abstract class GenericRepository&lt;TEntity,Tkey&gt;:IRepository&lt;TEntity&gt;,IDisposable
  where TEntity:BaseEntity&lt;Tkey&gt; 
  where Tkey:class
  
  
  public class UserRepository : GenericRepository&lt;User, string&gt;, IUserRepository
  {
      public UserRepository(SecurityDb dbContext) : base(dbContext)
      {
      }
  }
  </code></pre>
  
  <p>My Question is: I want to find the <code>UserRepository</code> through <code>GenericRepository&lt;&gt;</code>  and <code>IUserRepository</code> through <code>IRepository&lt;&gt;</code>. So I make this function:</p>
  
  <pre><code>    public static IServiceCollection AddIgidiaService(this IServiceCollection service,IEnumerable&lt;Assembly&gt; Assemblies)
      {
  
         var types= Assemblies.SelectMany(a=&gt;a.ExportedTypes).ToArray();
         var repositories= types.Where(t=&gt;typeof(GenericRepository&lt;,&gt;).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo()))
         .Where(t =&gt; !t.GetTypeInfo().IsAbstract);
         var irepositories=types.Where(t=&gt;typeof(IRepository&lt;&gt;).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo()))
              .Where(t=&gt;t.GetTypeInfo().IsInterface);
              foreach (var repository in repositories)
              {
                  foreach (var irepositoriy in irepositories)
                  {
                      if (repository.GetTypeInfo().IsInstanceOfType(irepositoriy))
                      {
                          service.AddScoped(repository,irepositoriy);
                      }
                  }
              }
          return service;
      }
  </code></pre>
  
  <p>This code does not work as I want it to.</p>