admin管理员组文章数量:1122832
I am implementing an extension for EF Core. It will include:
- an interceptor
- changes to the schema
- a custom convention
This means calling extension methods in DbContext.OnConfiguring
(for the interceptor), DbContext.ConfigureConventions
(for the convention), and DbContext.OnModelCreating
(for the schema changes). For example:
public class MyContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.AddMySchemaChanges();
base.OnModelCreating(modelBuilder);
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.AddMyInterceptor();
base.OnConfiguring(optionsBuilder);
}
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder.AddMyConvention();
base.ConfigureConventions(configurationBuilder);
}
}
Now, I find this most inconvenient, and would like to have a single point where I invoke my extension method. But, this requires that I have access to the DbContext
internals, for example, to where the conventions, interceptors, and model, are stored, and would probably be unsafe and not recommended (would like to avoid reflection, if possible). Something like:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.AddAllMyStuff();
base.OnConfiguring(optionsBuilder);
}
This would even allow to configure all my stuff from the outside, e.g., from the AddDbContext
method.
Can anyone provide advice on this? Is there any pattern for dealing with this situation?
本文标签: netGetting EF Core Internal InformationStack Overflow
版权声明:本文标题:.net - Getting EF Core Internal Information - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736301104a1931061.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论