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 Context
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var typeToRegisters = new List<Type>();
foreach (var module in GlobalConfiguration.Modules)
{
typeToRegisters.AddRange(module.Assembly.DefinedTypes.Select(t => t.AsType()));
}
RegisterEntities(modelBuilder, typeToRegisters);
base.OnModelCreating(modelBuilder);
}
private static void RegisterEntities(ModelBuilder modelBuilder, IEnumerable<Type> typeToRegisters)
{
var entityTypes = typeToRegisters.Where(x => x.GetTypeInfo().IsSubclassOf(typeof(IEntity<>)) && !x.GetTypeInfo().IsAbstract);
foreach (var type in entityTypes)
{
modelBuilder.Entity(type);
}
}
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.
is there any way that each module bring it's own migration? or any way to solve this?
Sorry for my bad English
Thanks