Skip to content

Commit

Permalink
Clean up a few more pubternals
Browse files Browse the repository at this point in the history
* Make NoopExecutionStrategy public
* Made parameterless ModelBuilder constructor public and use it to create initial Model
* Made NonCapturingLazyInitializer real internal and shared
  • Loading branch information
ajcvickers committed Apr 5, 2020
1 parent f6978f0 commit 7ee60f4
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 193 deletions.
7 changes: 2 additions & 5 deletions src/EFCore.Relational/Infrastructure/ModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ public abstract class ModelSnapshot

private IModel CreateModel()
{
#pragma warning disable EF1001 // Internal EF Core API usage.
var model = new Model();
var modelBuilder = new ModelBuilder(model);
var modelBuilder = new ModelBuilder();

BuildModel(modelBuilder);

return model;
#pragma warning restore EF1001 // Internal EF Core API usage.
return modelBuilder.Model;
}

/// <summary>
Expand Down
7 changes: 2 additions & 5 deletions src/EFCore.Relational/Migrations/Migration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,11 @@ public virtual IModel TargetModel
{
IModel Create()
{
#pragma warning disable EF1001 // Internal EF Core API usage.
var model = new Model();
var modelBuilder = new ModelBuilder(model);
var modelBuilder = new ModelBuilder();
BuildTargetModel(modelBuilder);

model = (Model)RelationalModel.Add(model, null);
var model = (IMutableModel)RelationalModel.Add((IConventionModel)modelBuilder.Model, null);
return model.FinalizeModel();
#pragma warning restore EF1001 // Internal EF Core API usage.
}

return _targetModel ??= Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public RelationalExecutionStrategyFactory([NotNull] ExecutionStrategyDependencie
/// current database provider.
/// </summary>
protected virtual IExecutionStrategy CreateDefaultStrategy([NotNull] ExecutionStrategyDependencies dependencies)
#pragma warning disable EF1001 // Internal EF Core API usage.
=> new NoopExecutionStrategy(Dependencies);
#pragma warning restore EF1001 // Internal EF Core API usage.

/// <summary>
/// Creates an <see cref="IExecutionStrategy" /> for the current database provider.
Expand Down
2 changes: 0 additions & 2 deletions src/EFCore.Relational/Update/ModificationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ public virtual EntityState EntityState
/// The list of <see cref="ColumnModification" />s needed to perform the insert, update, or delete.
/// </summary>
public virtual IReadOnlyList<ColumnModification> ColumnModifications
#pragma warning disable EF1001 // Internal EF Core API usage.
=> NonCapturingLazyInitializer.EnsureInitialized(
#pragma warning restore EF1001 // Internal EF Core API usage.
ref _columnModifications, this, command => command.GenerateColumnModifications());

/// <summary>
Expand Down
109 changes: 0 additions & 109 deletions src/EFCore/Internal/NonCapturingLazyInitializer.cs

This file was deleted.

13 changes: 4 additions & 9 deletions src/EFCore/ModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,12 @@ public ModelBuilder([NotNull] ConventionSet 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.
/// Initializes a new instance of the <see cref="ModelBuilder" /> class with no conventions.
/// Warning: conventions are typically needed to build a correct model.
/// </summary>
[EntityFrameworkInternal]
public ModelBuilder([NotNull] IMutableModel model)
public ModelBuilder()
{
Check.NotNull(model, nameof(model));

_builder = ((Model)model).Builder;
_builder = new Model().Builder;
}

/// <summary>
Expand Down
59 changes: 0 additions & 59 deletions src/EFCore/Storage/Internal/NoopExecutionStrategy.cs

This file was deleted.

75 changes: 75 additions & 0 deletions src/EFCore/Storage/NoopExecutionStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;

namespace Microsoft.EntityFrameworkCore.Storage
{
/// <summary>
/// An implementation of <see cref="IExecutionStrategy" /> that does no retries.
/// </summary>
public sealed class NoopExecutionStrategy : IExecutionStrategy
{
private ExecutionStrategyDependencies Dependencies { get; }

/// <summary>
/// Always returns false, since the <see cref="NoopExecutionStrategy" /> does not perform retries.
/// </summary>
public bool RetriesOnFailure => false;

/// <summary>
/// Constructs a new <see cref="NoopExecutionStrategy" /> with the given service dependencies.
/// </summary>
/// <param name="dependencies"> Dependencies for this execution strategy. </param>
public NoopExecutionStrategy([NotNull] ExecutionStrategyDependencies dependencies)
=> Dependencies = dependencies;

/// <summary>
/// Executes the specified operation and returns the result.
/// </summary>
/// <param name="state"> The state that will be passed to the operation. </param>
/// <param name="operation">
/// A delegate representing an executable operation that returns the result of type <typeparamref name="TResult" />.
/// </param>
/// <param name="verifySucceeded"> A delegate that tests whether the operation succeeded even though an exception was thrown. </param>
/// <typeparam name="TState"> The type of the state. </typeparam>
/// <typeparam name="TResult"> The return type of <paramref name="operation" />. </typeparam>
/// <returns> The result from the operation. </returns>
/// <exception cref="RetryLimitExceededException">
/// The operation has not succeeded after the configured number of retries.
/// </exception>
public TResult Execute<TState, TResult>(
TState state, Func<DbContext, TState, TResult> operation, Func<DbContext, TState, ExecutionResult<TResult>> verifySucceeded)
=> operation(Dependencies.CurrentContext.Context, state);

/// <summary>
/// Executes the specified asynchronous operation and returns the result.
/// </summary>
/// <param name="state"> The state that will be passed to the operation. </param>
/// <param name="operation">
/// A function that returns a started task of type <typeparamref name="TResult" />.
/// </param>
/// <param name="verifySucceeded"> A delegate that tests whether the operation succeeded even though an exception was thrown. </param>
/// <param name="cancellationToken">
/// A cancellation token used to cancel the retry operation, but not operations that are already in flight
/// or that already completed successfully.
/// </param>
/// <typeparam name="TState"> The type of the state. </typeparam>
/// <typeparam name="TResult"> The result type of the <see cref="Task{T}" /> returned by <paramref name="operation" />. </typeparam>
/// <returns>
/// A task that will run to completion if the original task completes successfully (either the
/// first time or after retrying transient failures). If the task fails with a non-transient error or
/// the retry limit is reached, the returned task will become faulted and the exception must be observed.
/// </returns>
/// <exception cref="RetryLimitExceededException">
/// The operation has not succeeded after the configured number of retries.
/// </exception>
public Task<TResult> ExecuteAsync<TState, TResult>(
TState state, Func<DbContext, TState, CancellationToken, Task<TResult>> operation, Func<DbContext, TState,
CancellationToken, Task<ExecutionResult<TResult>>> verifySucceeded, CancellationToken cancellationToken = default)
=> operation(Dependencies.CurrentContext.Context, state, cancellationToken);
}
}
Loading

0 comments on commit 7ee60f4

Please sign in to comment.