Skip to content

Commit

Permalink
Query: Don't expose ICurrentDbContext on QCCD
Browse files Browse the repository at this point in the history
Resolves #17845
  • Loading branch information
smitpatel committed Nov 19, 2019
1 parent 5385755 commit 8e17a77
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/EFCore/Query/QueryCompilationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ public QueryCompilationContext(
QueryCompilationContextDependencies dependencies,
bool async)
{
var context = dependencies.CurrentContext.Context;

IsAsync = async;
IsTracking = context.ChangeTracker.QueryTrackingBehavior == QueryTrackingBehavior.TrackAll;
IsTracking = dependencies.IsTracking;
IsBuffering = dependencies.IsRetryingExecutionStrategy;
Model = dependencies.Model;
ContextOptions = dependencies.ContextOptions;
ContextType = context.GetType();
ContextType = dependencies.ContextType;
Logger = dependencies.Logger;

_queryTranslationPreprocessorFactory = dependencies.QueryTranslationPreprocessorFactory;
Expand Down
29 changes: 18 additions & 11 deletions src/EFCore/Query/QueryCompilationContextDependencies.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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 JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand Down Expand Up @@ -37,6 +38,7 @@ namespace Microsoft.EntityFrameworkCore.Query
public sealed class QueryCompilationContextDependencies
{
private readonly IExecutionStrategyFactory _executionStrategyFactory;
private readonly ICurrentDbContext _currentContext;

/// <summary>
/// <para>
Expand Down Expand Up @@ -79,7 +81,7 @@ public QueryCompilationContextDependencies(
Check.NotNull(contextOptions, nameof(contextOptions));
Check.NotNull(logger, nameof(logger));

CurrentContext = currentContext;
_currentContext = currentContext;
Model = model;
QueryTranslationPreprocessorFactory = queryTranslationPreprocessorFactory;
QueryableMethodTranslatingExpressionVisitorFactory = queryableMethodTranslatingExpressionVisitorFactory;
Expand All @@ -92,9 +94,14 @@ public QueryCompilationContextDependencies(
}

/// <summary>
/// The cache being used to store value generator instances.
/// The CLR type of DbContext.
/// </summary>
public ICurrentDbContext CurrentContext { get; }
public Type ContextType => _currentContext.Context.GetType();

/// <summary>
/// The flag indicating if default query tracking behavior is tracking.
/// </summary>
public bool IsTracking => _currentContext.Context.ChangeTracker.QueryTrackingBehavior == QueryTrackingBehavior.TrackAll;

/// <summary>
/// The model.
Expand Down Expand Up @@ -149,7 +156,7 @@ public QueryCompilationContextDependencies With([NotNull] IModel model)
QueryTranslationPostprocessorFactory,
ShapedQueryCompilingExpressionVisitorFactory,
_executionStrategyFactory,
CurrentContext,
_currentContext,
ContextOptions,
Logger);

Expand All @@ -166,7 +173,7 @@ public QueryCompilationContextDependencies With([NotNull] IQueryTranslationPrepr
QueryTranslationPostprocessorFactory,
ShapedQueryCompilingExpressionVisitorFactory,
_executionStrategyFactory,
CurrentContext,
_currentContext,
ContextOptions,
Logger);

Expand All @@ -184,7 +191,7 @@ public QueryCompilationContextDependencies With(
QueryTranslationPostprocessorFactory,
ShapedQueryCompilingExpressionVisitorFactory,
_executionStrategyFactory,
CurrentContext,
_currentContext,
ContextOptions,
Logger);

Expand All @@ -202,7 +209,7 @@ public QueryCompilationContextDependencies With(
queryTranslationPostprocessorFactory,
ShapedQueryCompilingExpressionVisitorFactory,
_executionStrategyFactory,
CurrentContext,
_currentContext,
ContextOptions,
Logger);

Expand All @@ -220,7 +227,7 @@ public QueryCompilationContextDependencies With(
QueryTranslationPostprocessorFactory,
shapedQueryCompilingExpressionVisitorFactory,
_executionStrategyFactory,
CurrentContext,
_currentContext,
ContextOptions,
Logger);

Expand All @@ -237,7 +244,7 @@ public QueryCompilationContextDependencies With([NotNull] IExecutionStrategyFact
QueryTranslationPostprocessorFactory,
ShapedQueryCompilingExpressionVisitorFactory,
executionStrategyFactory,
CurrentContext,
_currentContext,
ContextOptions,
Logger);

Expand Down Expand Up @@ -271,7 +278,7 @@ public QueryCompilationContextDependencies With([NotNull] IDbContextOptions cont
QueryTranslationPostprocessorFactory,
ShapedQueryCompilingExpressionVisitorFactory,
_executionStrategyFactory,
CurrentContext,
_currentContext,
contextOptions,
Logger);

Expand All @@ -288,7 +295,7 @@ public QueryCompilationContextDependencies With([NotNull] IDiagnosticsLogger<DbL
QueryTranslationPostprocessorFactory,
ShapedQueryCompilingExpressionVisitorFactory,
_executionStrategyFactory,
CurrentContext,
_currentContext,
ContextOptions,
logger);
}
Expand Down

0 comments on commit 8e17a77

Please sign in to comment.