Skip to content

Commit

Permalink
Update query service lifetimes and align dependency objects
Browse files Browse the repository at this point in the history
Fixes #17000
  • Loading branch information
ajcvickers committed Aug 10, 2019
1 parent ae7f03d commit e493b26
Show file tree
Hide file tree
Showing 35 changed files with 360 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.Cosmos.Query.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.
/// <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>
/// <para>
/// The service lifetime is <see cref="ServiceLifetime.Singleton" />. This means a single instance
/// is used by many <see cref="DbContext" /> instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped" />.
/// </para>
/// </summary>
public class CosmosQueryableMethodTranslatingExpressionVisitorFactory : IQueryableMethodTranslatingExpressionVisitorFactory
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
{
/// <summary>
/// <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>
/// <para>
/// The service lifetime is <see cref="ServiceLifetime.Singleton" />. This means a single instance
/// is used by many <see cref="DbContext" /> instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped" />.
/// </para>
/// </summary>
public class InMemoryQueryableMethodTranslatingExpressionVisitorFactory : IQueryableMethodTranslatingExpressionVisitorFactory
{
private readonly QueryableMethodTranslatingExpressionVisitorDependencies _dependencies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal
{
/// <summary>
/// <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>
/// <para>
/// The service lifetime is <see cref="ServiceLifetime.Singleton" />. This means a single instance
/// is used by many <see cref="DbContext" /> instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped" />.
/// </para>
/// </summary>
public class InMemoryShapedQueryOptimizerFactory : IShapedQueryOptimizerFactory
{
private readonly ShapedQueryOptimizerDependencies _dependencies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ public static readonly IDictionary<Type, ServiceCharacteristics> RelationalServi
{ typeof(IInterceptorAggregator), new ServiceCharacteristics(ServiceLifetime.Scoped, multipleRegistrations: true) },
{ typeof(IInterceptor), new ServiceCharacteristics(ServiceLifetime.Scoped, multipleRegistrations: true) },
{ typeof(IRelationalTypeMappingSourcePlugin), new ServiceCharacteristics(ServiceLifetime.Singleton, multipleRegistrations: true) },

// New Query Pipeline
{ typeof(IQuerySqlGeneratorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IRelationalSqlTranslatingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IMethodCallTranslatorProvider), new ServiceCharacteristics(ServiceLifetime.Singleton) },
Expand Down Expand Up @@ -159,8 +157,6 @@ public override EntityFrameworkServicesBuilder TryAddCoreServices()
TryAdd<IInterceptorAggregator, DbConnectionInterceptorAggregator>();
TryAdd<IInterceptorAggregator, DbTransactionInterceptorAggregator>();
TryAdd<IInterceptorAggregator, DbCommandInterceptorAggregator>();

// New Query pipeline
TryAdd<IQuerySqlGeneratorFactory, QuerySqlGeneratorFactory>();
TryAdd<IShapedQueryCompilingExpressionVisitorFactory, RelationalShapedQueryCompilingExpressionVisitorFactory>();
TryAdd<IQueryableMethodTranslatingExpressionVisitorFactory, RelationalQueryableMethodTranslatingExpressionVisitorFactory>();
Expand Down Expand Up @@ -188,6 +184,7 @@ public override EntityFrameworkServicesBuilder TryAddCoreServices()
.AddDependencySingleton<QuerySqlGeneratorDependencies>()
.AddDependencySingleton<RelationalShapedQueryCompilingExpressionVisitorDependencies>()
.AddDependencySingleton<RelationalShapedQueryOptimizerDependencies>()
.AddDependencySingleton<RelationalEvaluatableExpressionFilterDependencies>()
.AddDependencyScoped<MigrationsSqlGeneratorDependencies>()
.AddDependencyScoped<RelationalConventionSetBuilderDependencies>()
.AddDependencyScoped<ModificationCommandBatchFactoryDependencies>()
Expand All @@ -197,8 +194,7 @@ public override EntityFrameworkServicesBuilder TryAddCoreServices()
.AddDependencyScoped<RelationalCompiledQueryCacheKeyGeneratorDependencies>()
.AddDependencyScoped<RelationalConnectionDependencies>()
.AddDependencyScoped<RelationalDatabaseDependencies>()
.AddDependencyScoped<RelationalQueryContextDependencies>()
.AddDependencyScoped<RelationalEvaluatableExpressionFilterDependencies>();
.AddDependencyScoped<RelationalQueryContextDependencies>();

return base.TryAddCoreServices();
}
Expand Down
11 changes: 11 additions & 0 deletions src/EFCore.Relational/Query/IMemberTranslatorProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@
using System;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.Query
{
/// <summary>
/// <para>
/// Provides translations for object members to <see cref="SqlExpression"/> instances.
/// </para>
/// <para>
/// The service lifetime is <see cref="ServiceLifetime.Singleton"/>. This means a single instance
/// is used by many <see cref="DbContext"/> instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped"/>.
/// </para>
/// </summary>
public interface IMemberTranslatorProvider
{
SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType);
Expand Down
11 changes: 11 additions & 0 deletions src/EFCore.Relational/Query/IMethodCallTranslatorProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@
using System.Reflection;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.Query
{
/// <summary>
/// <para>
/// Provides translations for method calls to <see cref="SqlExpression"/> instances.
/// </para>
/// <para>
/// The service lifetime is <see cref="ServiceLifetime.Singleton"/>. This means a single instance
/// is used by many <see cref="DbContext"/> instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped"/>.
/// </para>
/// </summary>
public interface IMethodCallTranslatorProvider
{
SqlExpression Translate(IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments);
Expand Down
12 changes: 12 additions & 0 deletions src/EFCore.Relational/Query/IQuerySqlGeneratorFactory.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
// 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.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.Query
{
/// <summary>
/// <para>
/// A factory for creating <see cref="QuerySqlGenerator"/> instances.
/// </para>
/// <para>
/// The service lifetime is <see cref="ServiceLifetime.Singleton"/>. This means a single instance
/// is used by many <see cref="DbContext"/> instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped"/>.
/// </para>
/// </summary>
public interface IQuerySqlGeneratorFactory
{
QuerySqlGenerator Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.Query
{
/// <summary>
/// <para>
/// A factory for creating <see cref="RelationalSqlTranslatingExpressionVisitor"/> instances.
/// </para>
/// <para>
/// The service lifetime is <see cref="ServiceLifetime.Singleton"/>. This means a single instance
/// is used by many <see cref="DbContext"/> instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped"/>.
/// </para>
/// </summary>
public interface IRelationalSqlTranslatingExpressionVisitorFactory
{
RelationalSqlTranslatingExpressionVisitor Create(
Expand Down
11 changes: 11 additions & 0 deletions src/EFCore.Relational/Query/ISqlExpressionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.Query
{
/// <summary>
/// <para>
/// A factory for creating <see cref="SqlExpression"/> instances.
/// </para>
/// <para>
/// The service lifetime is <see cref="ServiceLifetime.Singleton"/>. This means a single instance
/// is used by many <see cref="DbContext"/> instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped"/>.
/// </para>
/// </summary>
public interface ISqlExpressionFactory
{
SqlExpression ApplyTypeMapping(SqlExpression sqlExpression, RelationalTypeMapping typeMapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.Query.Internal
{
/// <summary>
/// <para>
/// A factory for creating <see cref="QueryableMethodTranslatingExpressionVisitor"/> instances.
/// </para>
/// <para>
/// The service lifetime is <see cref="ServiceLifetime.Singleton"/>. This means a single instance
/// is used by many <see cref="DbContext"/> instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped"/>.
/// </para>
/// </summary>
public class RelationalQueryableMethodTranslatingExpressionVisitorFactory : IQueryableMethodTranslatingExpressionVisitorFactory
{
private readonly QueryableMethodTranslatingExpressionVisitorDependencies _dependencies;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
// 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.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.Query.Internal
{
/// <summary>
/// <para>
/// A factory for creating <see cref="RelationalShapedQueryCompilingExpressionVisitorFactory"/> instances.
/// </para>
/// <para>
/// The service lifetime is <see cref="ServiceLifetime.Singleton"/>. This means a single instance
/// is used by many <see cref="DbContext"/> instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped"/>.
/// </para>
/// </summary>
public class RelationalShapedQueryCompilingExpressionVisitorFactory : IShapedQueryCompilingExpressionVisitorFactory
{
private readonly ShapedQueryCompilingExpressionVisitorDependencies _dependencies;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
// 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.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.Query.Internal
{
/// <summary>
/// <para>
/// A factory for creating <see cref="ShapedQueryOptimizer"/> instances.
/// </para>
/// <para>
/// The service lifetime is <see cref="ServiceLifetime.Singleton"/>. This means a single instance
/// is used by many <see cref="DbContext"/> instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped"/>.
/// </para>
/// </summary>
public class RelationalShapedQueryOptimizerFactory : IShapedQueryOptimizerFactory
{
private readonly ShapedQueryOptimizerDependencies _dependencies;
Expand Down
Loading

0 comments on commit e493b26

Please sign in to comment.