title: EF Core in Modular System
body: <p>I'm start developing modular system with asp.net core.
  the system has module loader, module installer and so on.
  each module has it's own database model that dynamically add to <code>Context</code></p>
  
  <pre><code>protected override void OnModelCreating(ModelBuilder modelBuilder)
  {
        var typeToRegisters = new List&lt;Type&gt;();
        foreach (var module in GlobalConfiguration.Modules)
        {
            typeToRegisters.AddRange(module.Assembly.DefinedTypes.Select(t =&gt; t.AsType()));
        }
  
        RegisterEntities(modelBuilder, typeToRegisters);
        base.OnModelCreating(modelBuilder);
  }
  
  private static void RegisterEntities(ModelBuilder modelBuilder, IEnumerable&lt;Type&gt; typeToRegisters)
  {
        var entityTypes = typeToRegisters.Where(x =&gt; x.GetTypeInfo().IsSubclassOf(typeof(IEntity&lt;&gt;)) &amp;&amp; !x.GetTypeInfo().IsAbstract);
        foreach (var type in entityTypes)
        {
            modelBuilder.Entity(type);
        }
  }
  </code></pre>
  
  <p>But EF Core doesn't work without migration.
  i can create all the migrations file for all modules and run it in start, but it's wrong. maybe a module doesn't need to be install at all.</p>
  
  <p>is there any way that each module bring it's own migration?
  or any way to solve this?</p>
  
  <p>Sorry for my bad English</p>
  
  <p>Thanks</p>