-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pre-convention model configuration infrastructure #24993
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,10 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal | |
public class Model : ConventionAnnotatable, IMutableModel, IConventionModel, IRuntimeModel | ||
{ | ||
/// <summary> | ||
/// The CLR type that is used for property bag entity types when no other type is specified. | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// 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 static readonly Type DefaultPropertyBagType = typeof(Dictionary<string, object>); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. attribute? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already pubturnal |
||
|
||
|
@@ -49,11 +52,11 @@ public class Model : ConventionAnnotatable, IMutableModel, IConventionModel, IRu | |
|
||
private ConventionDispatcher? _conventionDispatcher; | ||
private IList<IModelFinalizedConvention>? _modelFinalizedConventions; | ||
private ModelDependencies? _scopedModelDependencies; | ||
private bool? _skipDetectChanges; | ||
private ChangeTrackingStrategy? _changeTrackingStrategy; | ||
|
||
private ConfigurationSource? _changeTrackingStrategyConfigurationSource; | ||
private ModelDependencies? _scopedModelDependencies; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
|
@@ -72,7 +75,7 @@ public Model() | |
/// 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 Model(ConventionSet conventions, ModelDependencies? modelDependencies = null) | ||
public Model(ConventionSet conventions, ModelDependencies? modelDependencies = null, ModelConfiguration? modelConfiguration = null) | ||
{ | ||
if (modelDependencies != null) | ||
{ | ||
|
@@ -83,6 +86,7 @@ public Model(ConventionSet conventions, ModelDependencies? modelDependencies = n | |
_conventionDispatcher = dispatcher; | ||
_modelFinalizedConventions = conventions.ModelFinalizedConventions; | ||
Builder = builder; | ||
Configuration = modelConfiguration; | ||
dispatcher.OnModelInitialized(builder); | ||
} | ||
|
||
|
@@ -124,6 +128,14 @@ public virtual ModelDependencies? ScopedModelDependencies | |
/// </summary> | ||
public virtual InternalModelBuilder Builder { [DebuggerStepThrough] get; } | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// 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 virtual ModelConfiguration? Configuration { get; private set; } | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
|
@@ -575,7 +587,7 @@ public virtual bool IsShared(Type type) | |
/// </summary> | ||
public virtual ConfigurationSource? FindIgnoredConfigurationSource(string name) | ||
=> _ignoredTypeNames.TryGetValue(Check.NotEmpty(name, nameof(name)), out var ignoredConfigurationSource) | ||
? (ConfigurationSource?)ignoredConfigurationSource | ||
? ignoredConfigurationSource | ||
: null; | ||
|
||
/// <summary> | ||
|
@@ -859,6 +871,7 @@ public virtual IModel FinalizeModel() | |
|
||
if (finalizedModel is Model model) | ||
{ | ||
model.Configuration = null; | ||
finalizedModel = model.MakeReadonly(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Metadata.Internal | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// 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 partial class ModelConfiguration | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// 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 ModelConfiguration() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// 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 virtual bool IsEmpty() | ||
=> true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.ComponentModel; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata.Conventions; | ||
using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
|
||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// Provides a simple API surface for setting defaults and configuring conventions before they run. | ||
/// </para> | ||
/// <para> | ||
/// You can use <see cref="ModelConfigurationBuilder" /> to configure the conventions for a context by overriding | ||
/// <see cref="DbContext.ConfigureConventions(ModelConfigurationBuilder)" /> on your derived context. | ||
/// Alternatively you can create the model externally and set it on a <see cref="DbContextOptions" /> instance | ||
/// that is passed to the context constructor. | ||
/// </para> | ||
/// </summary> | ||
public class ModelConfigurationBuilder | ||
{ | ||
private readonly ModelConfiguration _modelConfiguration = new(); | ||
private readonly ConventionSet _conventions; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ModelConfigurationBuilder" />. | ||
/// </summary> | ||
/// <param name="conventions"> The conventions to be applied during model building. </param> | ||
public ModelConfigurationBuilder(ConventionSet conventions) | ||
{ | ||
Check.NotNull(conventions, nameof(conventions)); | ||
|
||
_conventions = conventions; | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// 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> | ||
[EntityFrameworkInternal] | ||
protected virtual ModelConfiguration ModelConfiguration => _modelConfiguration; | ||
|
||
/// <summary> | ||
/// Creates the configured <see cref="ModelBuilder" /> used to create the model. This is done automatically when using | ||
/// <see cref="DbContext.OnModelCreating" />; this method allows it to be run | ||
/// explicitly in cases where the automatic execution is not possible. | ||
/// </summary> | ||
/// <param name="modelDependencies"> The dependencies object used during model building. </param> | ||
/// <returns> The configured <see cref="ModelBuilder" />. </returns> | ||
public virtual ModelBuilder CreateModelBuilder(ModelDependencies? modelDependencies) | ||
=> new(_conventions, modelDependencies, _modelConfiguration.IsEmpty() ? null : _modelConfiguration); | ||
|
||
#region Hidden System.Object members | ||
|
||
/// <summary> | ||
/// Returns a string that represents the current object. | ||
/// </summary> | ||
/// <returns> A string that represents the current object. </returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public override string? ToString() | ||
=> base.ToString(); | ||
|
||
/// <summary> | ||
/// Determines whether the specified object is equal to the current object. | ||
/// </summary> | ||
/// <param name="obj"> The object to compare with the current object. </param> | ||
/// <returns> <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" />. </returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public override bool Equals(object? obj) | ||
=> base.Equals(obj); | ||
|
||
/// <summary> | ||
/// Serves as the default hash function. | ||
/// </summary> | ||
/// <returns> A hash code for the current object. </returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public override int GetHashCode() | ||
=> base.GetHashCode(); | ||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to the rest of the PR, I was just annoyed that we lost the stack trace