@ -26,8 +26,12 @@ public class AbpDbContextOptions
internal Dictionary < Type , List < object > > ConventionActions { get ; }
internal Action < DbContext , ModelBuilder > ? DefaultOnModelCreatingAction { get ; set ; }
internal Action < DbContext , DbContextOptionsBuilder > ? DefaultOnConfiguringAction { get ; set ; }
internal Dictionary < Type , List < object > > OnModelCreatingActions { get ; }
internal Dictionary < Type , List < object > > OnConfiguringActions { get ; }
public AbpDbContextOptions ( )
{
@ -37,6 +41,7 @@ public class AbpDbContextOptions
DbContextReplacements = new Dictionary < MultiTenantDbContextType , Type > ( ) ;
ConventionActions = new Dictionary < Type , List < object > > ( ) ;
OnModelCreatingActions = new Dictionary < Type , List < object > > ( ) ;
OnConfiguringActions = new Dictionary < Type , List < object > > ( ) ;
}
public void PreConfigure ( [ NotNull ] Action < AbpDbContextConfigurationContext > action )
@ -84,6 +89,13 @@ public class AbpDbContextOptions
DefaultOnModelCreatingAction = action ;
}
public void ConfigureDefaultOnConfiguring ( [ NotNull ] Action < DbContext , DbContextOptionsBuilder > action )
{
Check . NotNull ( action , nameof ( action ) ) ;
DefaultOnConfiguringAction = action ;
}
public void ConfigureOnModelCreating < TDbContext > ( [ NotNull ] Action < TDbContext , ModelBuilder > action )
where TDbContext : AbpDbContext < TDbContext >
@ -102,6 +114,24 @@ public class AbpDbContextOptions
actions . Add ( action ) ;
}
public void ConfigureOnConfiguring < TDbContext > ( [ NotNull ] Action < TDbContext , DbContextOptionsBuilder > action )
where TDbContext : AbpDbContext < TDbContext >
{
Check . NotNull ( action , nameof ( action ) ) ;
var actions = OnConfiguringActions . GetOrDefault ( typeof ( TDbContext ) ) ;
if ( actions = = null )
{
OnConfiguringActions [ typeof ( TDbContext ) ] = new List < object >
{
new Action < DbContext , DbContextOptionsBuilder > ( ( dbContext , builder ) = > action ( ( TDbContext ) dbContext , builder ) )
} ;
return ;
}
actions . Add ( action ) ;
}
public bool IsConfiguredDefault ( )
{