Skip to content

Commit

Permalink
Rename IModelFinalizedConvention to IModelFinalizingConvention
Browse files Browse the repository at this point in the history
Introduce IModelFinalizedConvention that don't change the model

Part of #12846
  • Loading branch information
AndriySvyryd committed Feb 11, 2020
1 parent 4667074 commit 627b272
Show file tree
Hide file tree
Showing 48 changed files with 191 additions and 243 deletions.
10 changes: 3 additions & 7 deletions src/EFCore.Cosmos/Metadata/Conventions/ETagPropertyConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Conventions
/// <summary>
/// A convention that adds etag metadata on the concurrency token, if present.
/// </summary>
public class ETagPropertyConvention : IModelFinalizedConvention
public class ETagPropertyConvention : IModelFinalizingConvention
{
/// <summary>
/// Called after a model is finalized.
/// </summary>
/// <param name="modelBuilder"> The builder for the model. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessModelFinalized(
/// <inheritdoc />
public virtual void ProcessModelFinalizing(
IConventionModelBuilder modelBuilder,
IConventionContext<IConventionModelBuilder> context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ public override ConventionSet CreateConventionSet()
var conventionSet = base.CreateConventionSet();

conventionSet.ModelInitializedConventions.Add(new ContextContainerConvention(Dependencies));
ConventionSet.AddBefore(
conventionSet.ModelFinalizedConventions,
new ETagPropertyConvention(),
typeof(ValidatingConvention));

conventionSet.ModelFinalizingConventions.Add(new ETagPropertyConvention());

var discriminatorConvention = new CosmosDiscriminatorConvention(Dependencies);
var storeKeyConvention = new StoreKeyConvention(Dependencies);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,11 @@ public virtual ConventionSet ModifyConventions(ConventionSet conventionSet)
new ProxyChangeTrackingConvention(extension),
typeof(DbSetFindingConvention));

ConventionSet.AddBefore(
conventionSet.ModelFinalizedConventions,
new ProxyBindingRewriter(
conventionSet.ModelFinalizingConventions.Add(new ProxyBindingRewriter(
_proxyFactory,
extension,
_lazyLoaderParameterBindingFactoryDependencies,
_conventionSetBuilderDependencies),
typeof(ValidatingConvention));
_conventionSetBuilderDependencies));

return conventionSet;
}
Expand Down
12 changes: 4 additions & 8 deletions src/EFCore.Proxies/Proxies/Internal/ProxyBindingRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Microsoft.EntityFrameworkCore.Proxies.Internal
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public class ProxyBindingRewriter : IModelFinalizedConvention
public class ProxyBindingRewriter : IModelFinalizingConvention
{
private static readonly MethodInfo _createLazyLoadingProxyMethod
= typeof(IProxyFactory).GetTypeInfo().GetDeclaredMethod(nameof(IProxyFactory.CreateLazyLoadingProxy));
Expand Down Expand Up @@ -57,12 +57,8 @@ public ProxyBindingRewriter(
_directBindingConvention = new ConstructorBindingConvention(conventionSetBuilderDependencies);
}

/// <summary>
/// Called after a model is finalized.
/// </summary>
/// <param name="modelBuilder"> The builder for the model. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessModelFinalized(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
/// <inheritdoc />
public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
{
if (_options?.UseProxies == true)
{
Expand All @@ -81,7 +77,7 @@ public virtual void ProcessModelFinalized(IConventionModelBuilder modelBuilder,
var binding = (InstantiationBinding)entityType[CoreAnnotationNames.ConstructorBinding];
if (binding == null)
{
_directBindingConvention.ProcessModelFinalized(modelBuilder, context);
_directBindingConvention.ProcessModelFinalizing(modelBuilder, context);
}

// WARNING: This code is EF internal; it should not be copied. See #10789 #14554
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
/// <summary>
/// A convention configure type mapping for <see cref="IDbFunction" /> instances.
/// </summary>
public class DbFunctionTypeMappingConvention : IModelFinalizedConvention
public class DbFunctionTypeMappingConvention : IModelFinalizingConvention
{
private readonly IRelationalTypeMappingSource _relationalTypeMappingSource;

Expand All @@ -31,12 +31,8 @@ public DbFunctionTypeMappingConvention(
_relationalTypeMappingSource = (IRelationalTypeMappingSource)dependencies.TypeMappingSource;
}

/// <summary>
/// Called after a model is finalized.
/// </summary>
/// <param name="modelBuilder"> The builder for the model. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessModelFinalized(
/// <inheritdoc />
public virtual void ProcessModelFinalizing(
IConventionModelBuilder modelBuilder,
IConventionContext<IConventionModelBuilder> context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,11 @@ public override ConventionSet CreateConventionSet()
conventionSet.ModelInitializedConventions.Add(dbFunctionAttributeConvention);
conventionSet.ModelAnnotationChangedConventions.Add(dbFunctionAttributeConvention);

ConventionSet.AddBefore(
conventionSet.ModelFinalizedConventions,
storeGenerationConvention,
typeof(ValidatingConvention));
ConventionSet.AddBefore(
conventionSet.ModelFinalizedConventions,
new SharedTableConvention(Dependencies, RelationalDependencies),
typeof(ValidatingConvention));
ConventionSet.AddBefore(
conventionSet.ModelFinalizedConventions,
new DbFunctionTypeMappingConvention(Dependencies, RelationalDependencies),
typeof(ValidatingConvention));
conventionSet.ModelFinalizingConventions.Add(storeGenerationConvention);
conventionSet.ModelFinalizingConventions.Add(new SharedTableConvention(Dependencies, RelationalDependencies));
conventionSet.ModelFinalizingConventions.Add(new DbFunctionTypeMappingConvention(Dependencies, RelationalDependencies));
ReplaceConvention(
conventionSet.ModelFinalizedConventions,
conventionSet.ModelFinalizingConventions,
(QueryFilterDefiningQueryRewritingConvention)new RelationalQueryFilterDefiningQueryRewritingConvention(
Dependencies, RelationalDependencies));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
/// <summary>
/// A convention that manipulates names of database objects for entity types that share a table to avoid clashes.
/// </summary>
public class SharedTableConvention : IModelFinalizedConvention
public class SharedTableConvention : IModelFinalizingConvention
{
/// <summary>
/// Creates a new instance of <see cref="SharedTableConvention" />.
Expand All @@ -35,12 +35,8 @@ public SharedTableConvention(
/// </summary>
protected virtual ProviderConventionSetBuilderDependencies Dependencies { get; }

/// <summary>
/// Called after a model is finalized.
/// </summary>
/// <param name="modelBuilder"> The builder for the model. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessModelFinalized(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
/// <inheritdoc />
public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
{
var maxLength = modelBuilder.Metadata.GetMaxIdentifierLength();
var tables = new Dictionary<(string, string), List<IConventionEntityType>>();
Expand Down Expand Up @@ -73,6 +69,7 @@ private static void TryUniquifyTableNames(
foreach (var entityType in model.GetEntityTypes())
{
var tableName = (Schema: entityType.GetSchema(), TableName: entityType.GetTableName());

if (!tables.TryGetValue(tableName, out var entityTypes))
{
entityTypes = new List<IConventionEntityType>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
/// <summary>
/// A convention that ensures that properties aren't configured to have a default value and as computed column at the same time.
/// </summary>
public class StoreGenerationConvention : IPropertyAnnotationChangedConvention, IModelFinalizedConvention
public class StoreGenerationConvention : IPropertyAnnotationChangedConvention, IModelFinalizingConvention
{
/// <summary>
/// Creates a new instance of <see cref="StoreGenerationConvention" />.
Expand Down Expand Up @@ -86,12 +86,8 @@ public virtual void ProcessPropertyAnnotationChanged(
}
}

/// <summary>
/// Called after a model is finalized.
/// </summary>
/// <param name="modelBuilder"> The builder for the model. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessModelFinalized(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
/// <inheritdoc />
public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
{
foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,9 @@ public override ConventionSet CreateConventionSet()
ReplaceConvention(
conventionSet.PropertyAnnotationChangedConventions, (RelationalValueGenerationConvention)valueGenerationConvention);

ConventionSet.AddBefore(
conventionSet.ModelFinalizedConventions,
valueGenerationStrategyConvention,
typeof(ValidatingConvention));

ConventionSet.AddBefore(
conventionSet.ModelFinalizedConventions,
new SqlServerEnumConvention(Dependencies),
typeof(ValidatingConvention));

ReplaceConvention(conventionSet.ModelFinalizedConventions, storeGenerationConvention);
conventionSet.ModelFinalizingConventions.Add(valueGenerationStrategyConvention);
conventionSet.ModelFinalizingConventions.Add(new SqlServerEnumConvention(Dependencies));
ReplaceConvention(conventionSet.ModelFinalizingConventions, storeGenerationConvention);

return conventionSet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
/// <summary>
/// A convention that creates check constraint for Enum column in a model.
/// </summary>
public class SqlServerEnumConvention : IModelFinalizedConvention
public class SqlServerEnumConvention : IModelFinalizingConvention
{
/// <summary>
/// Creates a new instance of <see cref="SqlServerEnumConvention" />.
Expand All @@ -31,12 +31,8 @@ public SqlServerEnumConvention([NotNull] ProviderConventionSetBuilderDependencie
/// </summary>
protected virtual ProviderConventionSetBuilderDependencies Dependencies { get; }

/// <summary>
/// Called after a model is finalized.
/// </summary>
/// <param name="modelBuilder"> The builder for the model. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessModelFinalized(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
/// <inheritdoc />
public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
{
foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
/// A convention that configures the default model <see cref="SqlServerValueGenerationStrategy" /> as
/// <see cref="SqlServerValueGenerationStrategy.IdentityColumn" />.
/// </summary>
public class SqlServerValueGenerationStrategyConvention : IModelInitializedConvention, IModelFinalizedConvention
public class SqlServerValueGenerationStrategyConvention : IModelInitializedConvention, IModelFinalizingConvention
{
/// <summary>
/// Creates a new instance of <see cref="SqlServerValueGenerationStrategyConvention" />.
Expand Down Expand Up @@ -42,12 +42,8 @@ public virtual void ProcessModelInitialized(
modelBuilder.HasValueGenerationStrategy(SqlServerValueGenerationStrategy.IdentityColumn);
}

/// <summary>
/// Called after a model is finalized.
/// </summary>
/// <param name="modelBuilder"> The builder for the model. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessModelFinalized(
/// <inheritdoc />
public virtual void ProcessModelFinalizing(
IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
{
foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Infrastructure/ModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ModelValidator([NotNull] ModelValidatorDependencies dependencies)
/// <param name="logger"> The logger to use. </param>
public virtual void Validate(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
{
((Model)model).MakeReadonly();
((Model)model).IsValidated = true;

ValidateNoShadowEntities(model, logger);
ValidateIgnoredMembers(model, logger);
Expand Down
10 changes: 3 additions & 7 deletions src/EFCore/Metadata/Conventions/BackingFieldConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
public class BackingFieldConvention :
IPropertyAddedConvention,
INavigationAddedConvention,
IModelFinalizedConvention
IModelFinalizingConvention
{
/// <summary>
/// Creates a new instance of <see cref="BackingFieldConvention" />.
Expand Down Expand Up @@ -241,12 +241,8 @@ private static int PrefixBinarySearch<T>(KeyValuePair<string, T>[] array, string
}
}

/// <summary>
/// Called after a model is finalized.
/// </summary>
/// <param name="modelBuilder"> The builder for the model. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessModelFinalized(
/// <inheritdoc />
public virtual void ProcessModelFinalizing(
IConventionModelBuilder modelBuilder,
IConventionContext<IConventionModelBuilder> context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
/// A convention that sets a flag on the model to always skip detecting changes if no entity type is using the
/// <see cref="ChangeTrackingStrategy.Snapshot" /> strategy.
/// </summary>
public class ChangeTrackingStrategyConvention : IModelFinalizedConvention
public class ChangeTrackingStrategyConvention : IModelFinalizingConvention
{
/// <summary>
/// Creates a new instance of <see cref="ChangeTrackingStrategyConvention" />.
Expand All @@ -28,12 +28,8 @@ public ChangeTrackingStrategyConvention([NotNull] ProviderConventionSetBuilderDe
/// </summary>
protected virtual ProviderConventionSetBuilderDependencies Dependencies { get; }

/// <summary>
/// Called after a model is finalized.
/// </summary>
/// <param name="modelBuilder"> The builder for the model. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessModelFinalized(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
/// <inheritdoc />
public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
{
foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
{
Expand Down
10 changes: 3 additions & 7 deletions src/EFCore/Metadata/Conventions/ConstructorBindingConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
/// * m_[parameter name]
/// * m_[pascal-cased parameter name]
/// </summary>
public class ConstructorBindingConvention : IModelFinalizedConvention
public class ConstructorBindingConvention : IModelFinalizingConvention
{
/// <summary>
/// Creates a new instance of <see cref="ConstructorBindingConvention" />.
Expand All @@ -39,12 +39,8 @@ public ConstructorBindingConvention([NotNull] ProviderConventionSetBuilderDepend
/// </summary>
protected virtual ProviderConventionSetBuilderDependencies Dependencies { get; }

/// <summary>
/// Called after a model is finalized.
/// </summary>
/// <param name="modelBuilder"> The builder for the model. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessModelFinalized(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
/// <inheritdoc />
public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
{
foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
{
Expand Down
5 changes: 5 additions & 0 deletions src/EFCore/Metadata/Conventions/ConventionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public class ConventionSet
/// <summary>
/// Conventions to run when model building is completed.
/// </summary>
public virtual IList<IModelFinalizingConvention> ModelFinalizingConventions { get; } = new List<IModelFinalizingConvention>();

/// <summary>
/// Conventions to run when model validation is completed.
/// </summary>
public virtual IList<IModelFinalizedConvention> ModelFinalizedConventions { get; } = new List<IModelFinalizedConvention>();

/// <summary>
Expand Down
Loading

0 comments on commit 627b272

Please sign in to comment.