Skip to content

Instantly share code, notes, and snippets.

@rqx110
Created August 15, 2018 01:33
Show Gist options
  • Save rqx110/b14f22452b806ea0d039e78fa4eb8976 to your computer and use it in GitHub Desktop.
Save rqx110/b14f22452b806ea0d039e78fa4eb8976 to your computer and use it in GitHub Desktop.
EF core 2.0 批量注册entityTypeConfiguration
string typeName = typeof(IEntityTypeConfiguration<>).Name;
var assembly = Assembly.GetExecutingAssembly();
assembly.GetTypes()
.Where(w => w.GetTypeInfo().ImplementedInterfaces.Any(a => a.Name == typeName))
.ToList()
.ForEach(item =>
{
dynamic instance = item.FullName;
builder.ApplyConfiguration(assembly.CreateInstance(instance));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment