Skip to content
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

Clean up of pubternal usage for building/using internal service provider #20535

Merged
merged 1 commit into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
Expand Down Expand Up @@ -203,10 +202,8 @@ public static int ExecuteSqlRaw(
Check.NotNull(parameters, nameof(parameters));

var facadeDependencies = GetFacadeDependencies(databaseFacade);
#pragma warning disable EF1001 // Internal EF Core API usage.
var concurrencyDetector = facadeDependencies.ConcurrencyDetector;
var logger = facadeDependencies.CommandLogger;
#pragma warning restore EF1001 // Internal EF Core API usage.

using (concurrencyDetector.EnterCriticalSection())
{
Expand All @@ -220,9 +217,7 @@ public static int ExecuteSqlRaw(
facadeDependencies.RelationalConnection,
rawSqlCommand.ParameterValues,
null,
#pragma warning disable EF1001 // Internal EF Core API usage.
((IDatabaseFacadeDependenciesAccessor)databaseFacade).Context,
#pragma warning restore EF1001 // Internal EF Core API usage.
logger));
}
}
Expand Down Expand Up @@ -360,10 +355,8 @@ public static async Task<int> ExecuteSqlRawAsync(
Check.NotNull(parameters, nameof(parameters));

var facadeDependencies = GetFacadeDependencies(databaseFacade);
#pragma warning disable EF1001 // Internal EF Core API usage.
var concurrencyDetector = facadeDependencies.ConcurrencyDetector;
var logger = facadeDependencies.CommandLogger;
#pragma warning restore EF1001 // Internal EF Core API usage.

using (concurrencyDetector.EnterCriticalSection())
{
Expand All @@ -377,9 +370,7 @@ public static async Task<int> ExecuteSqlRawAsync(
facadeDependencies.RelationalConnection,
rawSqlCommand.ParameterValues,
null,
#pragma warning disable EF1001 // Internal EF Core API usage.
((IDatabaseFacadeDependenciesAccessor)databaseFacade).Context,
#pragma warning restore EF1001 // Internal EF Core API usage.
logger),
cancellationToken);
}
Expand Down Expand Up @@ -620,15 +611,11 @@ public static string GenerateCreateScript([NotNull] this DatabaseFacade database
/// <param name="databaseFacade"> The facade from <see cref="DbContext.Database" />. </param>
/// <returns> True if a relational database provider is being used; false otherwise. </returns>
public static bool IsRelational([NotNull] this DatabaseFacade databaseFacade)
#pragma warning disable EF1001 // Internal EF Core API usage.
=> ((IDatabaseFacadeDependenciesAccessor)Check.NotNull(databaseFacade, nameof(databaseFacade))).Dependencies is IRelationalDatabaseFacadeDependencies;
#pragma warning restore EF1001 // Internal EF Core API usage.

private static IRelationalDatabaseFacadeDependencies GetFacadeDependencies(DatabaseFacade databaseFacade)
{
#pragma warning disable EF1001 // Internal EF Core API usage.
var dependencies = ((IDatabaseFacadeDependenciesAccessor)databaseFacade).Dependencies;
#pragma warning restore EF1001 // Internal EF Core API usage.

if (dependencies is IRelationalDatabaseFacadeDependencies relationalDependencies)
{
Expand All @@ -652,8 +639,6 @@ private static TService GetRelationalService<TService>(this IInfrastructure<ISer
}

private static IDbContextTransactionManager GetTransactionManager([NotNull] this DatabaseFacade databaseFacade)
#pragma warning disable EF1001 // Internal EF Core API usage.
=> ((IDatabaseFacadeDependenciesAccessor)Check.NotNull(databaseFacade, nameof(databaseFacade))).Dependencies.TransactionManager;
#pragma warning restore EF1001 // Internal EF Core API usage.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class EntityFrameworkRelationalServicesBuilder : EntityFrameworkServicesB
/// </summary>
[EntityFrameworkInternal]
public static readonly IDictionary<Type, ServiceCharacteristics> RelationalServices
#pragma warning disable EF1001 // Internal EF Core API usage.
= new Dictionary<Type, ServiceCharacteristics>
{
{ typeof(IKeyValueIndexFactorySource), new ServiceCharacteristics(ServiceLifetime.Singleton) },
Expand Down Expand Up @@ -95,7 +94,6 @@ public static readonly IDictionary<Type, ServiceCharacteristics> RelationalServi
{ typeof(IMemberTranslatorPlugin), new ServiceCharacteristics(ServiceLifetime.Singleton, multipleRegistrations: true) },
{ typeof(IRelationalParameterBasedQueryTranslationPostprocessorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) }
};
#pragma warning restore EF1001 // Internal EF Core API usage.

/// <summary>
/// Used by relational database providers to create a new <see cref="EntityFrameworkRelationalServicesBuilder" /> for
Expand All @@ -108,20 +106,15 @@ public EntityFrameworkRelationalServicesBuilder([NotNull] IServiceCollection ser
}

/// <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.
/// Gets the <see cref="EntityFrameworkServicesBuilder.ServiceCharacteristics" /> for the given service type.
/// </summary>
[EntityFrameworkInternal]
/// <param name="serviceType"> The type that defines the service API. </param>
/// <returns> The <see cref="EntityFrameworkServicesBuilder.ServiceCharacteristics" /> for the type. </returns>
/// <exception cref="InvalidOperationException"> when the type is not an EF service. </exception>
protected override ServiceCharacteristics GetServiceCharacteristics(Type serviceType)
{
return RelationalServices.TryGetValue(serviceType, out var characteristics)
=> RelationalServices.TryGetValue(serviceType, out var characteristics)
? characteristics
#pragma warning disable EF1001 // Internal EF Core API usage.
: base.GetServiceCharacteristics(serviceType);
#pragma warning restore EF1001 // Internal EF Core API usage.
}

/// <summary>
/// Registers default implementations of all services, including relational services, not already
Expand Down Expand Up @@ -177,7 +170,6 @@ public override EntityFrameworkServicesBuilder TryAddCoreServices()
TryAdd<IRelationalParameterBasedQueryTranslationPostprocessorFactory, RelationalParameterBasedQueryTranslationPostprocessorFactory>();
TryAdd<IRelationalQueryStringFactory, RelationalQueryStringFactory>();

#pragma warning disable EF1001 // Internal EF Core API usage.
ServiceCollectionMap.GetInfrastructure()
.AddDependencySingleton<RelationalSqlGenerationHelperDependencies>()
.AddDependencySingleton<RelationalTypeMappingSourceDependencies>()
Expand Down Expand Up @@ -210,7 +202,6 @@ public override EntityFrameworkServicesBuilder TryAddCoreServices()
.AddDependencyScoped<RelationalConnectionDependencies>()
.AddDependencyScoped<RelationalDatabaseDependencies>()
.AddDependencyScoped<RelationalQueryContextDependencies>();
#pragma warning restore EF1001 // Internal EF Core API usage.

return base.TryAddCoreServices();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@

namespace Microsoft.EntityFrameworkCore.Internal
{
#pragma warning disable EF1001 // Internal EF Core API usage.
public class RelationalDatabaseFacadeDependencies : DatabaseFacadeDependencies, IRelationalDatabaseFacadeDependencies
#pragma warning restore EF1001 // Internal EF Core API usage.
/// <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 class RelationalDatabaseFacadeDependencies : IRelationalDatabaseFacadeDependencies
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -28,18 +32,66 @@ public RelationalDatabaseFacadeDependencies(
[NotNull] IConcurrencyDetector concurrencyDetector,
[NotNull] IRelationalConnection relationalConnection,
[NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder)
: base(
transactionManager,
databaseCreator,
executionStrategyFactory,
databaseProviders,
commandLogger,
concurrencyDetector)
{
TransactionManager = transactionManager;
DatabaseCreator = databaseCreator;
ExecutionStrategyFactory = executionStrategyFactory;
DatabaseProviders = databaseProviders;
CommandLogger = commandLogger;
ConcurrencyDetector = concurrencyDetector;
RelationalConnection = relationalConnection;
RawSqlCommandBuilder = rawSqlCommandBuilder;
}


/// <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 IDbContextTransactionManager TransactionManager { 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 IDatabaseCreator DatabaseCreator { 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 IExecutionStrategyFactory ExecutionStrategyFactory { 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 IEnumerable<IDatabaseProvider> DatabaseProviders { 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 IDiagnosticsLogger<DbLoggerCategory.Database.Command> CommandLogger { 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 IConcurrencyDetector ConcurrencyDetector { 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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.Storage
{
/// <summary>
/// <para>
/// Exposes dependencies needed by <see cref="DatabaseFacade" /> and its relational extension methods.
/// </para>
/// <para>
/// This type is typically used by database providers (and other extensions). It is generally
/// not used in application code.
/// </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 interface IRelationalDatabaseFacadeDependencies : IDatabaseFacadeDependencies
{
/// <summary>
/// The relational connection.
/// </summary>
IRelationalConnection RelationalConnection { get; }

/// <summary>
/// The raw SQL command builder.
/// </summary>
IRawSqlCommandBuilder RawSqlCommandBuilder { get; }
}
}
Loading