-
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
Make EvaluableExpressionFilter public #16776
Merged
+218
−45
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
77 changes: 77 additions & 0 deletions
77
src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilterDependencies.cs
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,77 @@ | ||
// 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 JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// Service dependencies parameter class for <see cref="RelationalEvaluatableExpressionFilter" /> | ||
/// </para> | ||
/// <para> | ||
/// This type is typically used by database providers (and other extensions). It is generally | ||
/// not used in application code. | ||
/// </para> | ||
/// <para> | ||
/// Do not construct instances of this class directly from either provider or application code as the | ||
/// constructor signature may change as new dependencies are added. Instead, use this type in | ||
/// your constructor so that an instance will be created and injected automatically by the | ||
/// dependency injection container. To create an instance with some dependent services replaced, | ||
/// first resolve the object from the dependency injection container, then replace selected | ||
/// services using the 'With...' methods. Do not call the constructor at any point in this process. | ||
/// </para> | ||
/// <para> | ||
/// The service lifetime is <see cref="ServiceLifetime.Scoped"/>. This means that each | ||
/// <see cref="DbContext"/> instance will use its own instance of this service. | ||
/// The implementation may depend on other services registered with any lifetime. | ||
/// The implementation does not need to be thread-safe. | ||
/// </para> | ||
/// </summary> | ||
public sealed class RelationalEvaluatableExpressionFilterDependencies | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// Creates the service dependencies parameter object for a <see cref="RelationalEvaluatableExpressionFilter" />. | ||
/// </para> | ||
/// <para> | ||
/// Do not call this constructor directly from either provider or application code as it may change | ||
/// as new dependencies are added. Instead, use this type in your constructor so that an instance | ||
/// will be created and injected automatically by the dependency injection container. To create | ||
/// an instance with some dependent services replaced, first resolve the object from the dependency | ||
/// injection container, then replace selected services using the 'With...' methods. Do not call | ||
/// the constructor at any point in this process. | ||
/// </para> | ||
/// <para> | ||
/// 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. | ||
/// </para> | ||
/// </summary> | ||
[EntityFrameworkInternal] | ||
public RelationalEvaluatableExpressionFilterDependencies([NotNull] IModel model) | ||
{ | ||
Check.NotNull(model, nameof(model)); | ||
|
||
Model = model; | ||
} | ||
|
||
/// <summary> | ||
/// The model used with this <see cref="RelationalEvaluatableExpressionFilter"/>. | ||
/// </summary> | ||
public IModel Model { get; } | ||
|
||
/// <summary> | ||
/// Clones this dependency parameter object with one service replaced. | ||
/// </summary> | ||
/// <param name="model"> A replacement for the current dependency of this type. </param> | ||
/// <returns> A new parameter object with the given service replaced. </returns> | ||
public RelationalEvaluatableExpressionFilterDependencies With([NotNull] IModel model) | ||
=> new RelationalEvaluatableExpressionFilterDependencies(model); | ||
} | ||
} | ||
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
58 changes: 58 additions & 0 deletions
58
src/EFCore/Query/EvaluatableExpressionFilterDependencies.cs
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,58 @@ | ||
// 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 Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// Service dependencies parameter class for <see cref="EvaluatableExpressionFilter" /> | ||
/// </para> | ||
/// <para> | ||
/// This type is typically used by database providers (and other extensions). It is generally | ||
/// not used in application code. | ||
/// </para> | ||
/// <para> | ||
/// Do not construct instances of this class directly from either provider or application code as the | ||
/// constructor signature may change as new dependencies are added. Instead, use this type in | ||
/// your constructor so that an instance will be created and injected automatically by the | ||
/// dependency injection container. To create an instance with some dependent services replaced, | ||
/// first resolve the object from the dependency injection container, then replace selected | ||
/// services using the 'With...' methods. Do not call the constructor at any point in this process. | ||
/// </para> | ||
/// <para> | ||
/// The service lifetime is <see cref="ServiceLifetime.Scoped"/>. This means that each | ||
/// <see cref="DbContext"/> instance will use its own instance of this service. | ||
/// The implementation may depend on other services registered with any lifetime. | ||
/// The implementation does not need to be thread-safe. | ||
/// </para> | ||
/// </summary> | ||
public sealed class EvaluatableExpressionFilterDependencies | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// Creates the service dependencies parameter object for a <see cref="EvaluatableExpressionFilter" />. | ||
/// </para> | ||
/// <para> | ||
/// Do not call this constructor directly from either provider or application code as it may change | ||
/// as new dependencies are added. Instead, use this type in your constructor so that an instance | ||
/// will be created and injected automatically by the dependency injection container. To create | ||
/// an instance with some dependent services replaced, first resolve the object from the dependency | ||
/// injection container, then replace selected services using the 'With...' methods. Do not call | ||
/// the constructor at any point in this process. | ||
/// </para> | ||
/// <para> | ||
/// 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. | ||
/// </para> | ||
/// </summary> | ||
[EntityFrameworkInternal] | ||
public EvaluatableExpressionFilterDependencies() | ||
{ | ||
} | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
src/EFCore/Query/Internal/EvaluatableExpressionFilterBase.cs
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
test/EFCore.Relational.Tests/Query/RelationalEvaluatableExpressionFilterDependenciesTest.cs
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,17 @@ | ||
// 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 Microsoft.EntityFrameworkCore.TestUtilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query | ||
{ | ||
public class RelationalEvaluatableExpressionFilterDependenciesTest | ||
{ | ||
[ConditionalFact] | ||
public void Can_use_With_methods_to_clone_and_replace_service() | ||
{ | ||
RelationalTestHelpers.Instance.TestDependenciesClone<RelationalEvaluatableExpressionFilterDependencies>(); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/EFCore.Tests/Query/EvaluatableExpressionFilterDependenciesTest.cs
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,17 @@ | ||
// 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 Microsoft.EntityFrameworkCore.TestUtilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query | ||
{ | ||
public class EvaluatableExpressionFilterDependenciesTest | ||
{ | ||
[ConditionalFact] | ||
public void Can_use_With_methods_to_clone_and_replace_service() | ||
{ | ||
InMemoryTestHelpers.Instance.TestDependenciesClone<EvaluatableExpressionFilterDependencies>(); | ||
} | ||
} | ||
} |
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.
With method?
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.
@roji Follow the same pattern as for all existing dependency objects and add validation test--see https://github.com/aspnet/EntityFrameworkCore/blob/master/test/EFCore.Tests/ModelSourceDependenciesTest.cs
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.
Added With method for Model and tests for both the core and relational dependencies (sorry, it's the first time I'm doing this).
Note that I added these because the API consistency tests told me too. I think there are various other cases of services without dependency objects (e.g. QueryContext accepts QueryContextDependencies, but RelationalQueryContext accepts additional parameters directly). We may want to do an extra pass for this.
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.
@roji Dependency objects are needed primarily when "outsiders" need to call constructors, possible from a derived class. This is expected anytime we have a public service implementation since, as you know from API review, we typically make these public when we expect people to inherit. So that's why there is a API consistency rule for those.
There are other places where we have added similar objects, but sometimes with a lighter-weight pattern (although maybe all our dependency objects could be read-only structs?). If there are places where you can see there will be problems evolving the API without dependency objects, then we should review those.
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.
OK, thanks for the explanation.
It seems a bit odd for a core base class (e.g. QueryContext) to have dependencies but not for its subclass in relational - if no outsider is expected to extend, then we don't need the deps in core, and if they do, then we do need them on relational, no?
Apart from that I don't yet have a good-enough feel for which services are expected to be extended (again, QueryContext?). It's probably not a big deal in any case.
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.
@roji Agreed that feels wrong. File an issue?
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.
Opened #16788