From 5fe6e5114b2ac98c1c6216f2c2073f627d858e3e Mon Sep 17 00:00:00 2001 From: Jimmy Campbell Date: Tue, 27 Jul 2021 09:27:53 -0700 Subject: [PATCH] Added cancellation token and configureawait. --- .../FeatureFlagDemo/HttpContextTargetingContextAccessor.cs | 3 ++- .../TagHelpers/FeatureTagHelper.cs | 4 ++-- .../Targeting/ITargetingContextAccessor.cs | 4 +++- src/Microsoft.FeatureManagement/Targeting/TargetingFilter.cs | 2 +- .../OnDemandTargetingContextAccessor.cs | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/FeatureFlagDemo/HttpContextTargetingContextAccessor.cs b/examples/FeatureFlagDemo/HttpContextTargetingContextAccessor.cs index 9f9c8964..931be833 100644 --- a/examples/FeatureFlagDemo/HttpContextTargetingContextAccessor.cs +++ b/examples/FeatureFlagDemo/HttpContextTargetingContextAccessor.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Security.Claims; +using System.Threading; using System.Threading.Tasks; namespace FeatureFlagDemo @@ -23,7 +24,7 @@ public HttpContextTargetingContextAccessor(IHttpContextAccessor httpContextAcces _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor)); } - public ValueTask GetContextAsync() + public ValueTask GetContextAsync(CancellationToken _) { HttpContext httpContext = _httpContextAccessor.HttpContext; diff --git a/src/Microsoft.FeatureManagement.AspNetCore/TagHelpers/FeatureTagHelper.cs b/src/Microsoft.FeatureManagement.AspNetCore/TagHelpers/FeatureTagHelper.cs index fc4a6c06..651c0068 100644 --- a/src/Microsoft.FeatureManagement.AspNetCore/TagHelpers/FeatureTagHelper.cs +++ b/src/Microsoft.FeatureManagement.AspNetCore/TagHelpers/FeatureTagHelper.cs @@ -56,8 +56,8 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu IEnumerable names = Name.Split(',').Select(n => n.Trim()); enabled = Requirement == RequirementType.All ? - await names.All(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false)) : - await names.Any(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false)); + await names.All(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false) : + await names.Any(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false); } if (Negate) diff --git a/src/Microsoft.FeatureManagement/Targeting/ITargetingContextAccessor.cs b/src/Microsoft.FeatureManagement/Targeting/ITargetingContextAccessor.cs index 94c1eebd..2739e628 100644 --- a/src/Microsoft.FeatureManagement/Targeting/ITargetingContextAccessor.cs +++ b/src/Microsoft.FeatureManagement/Targeting/ITargetingContextAccessor.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. // +using System.Threading; using System.Threading.Tasks; namespace Microsoft.FeatureManagement.FeatureFilters @@ -13,7 +14,8 @@ public interface ITargetingContextAccessor /// /// Retrieves the current targeting context. /// + /// The cancellation token to cancel the operation. /// The current targeting context. - ValueTask GetContextAsync(); + ValueTask GetContextAsync(CancellationToken cancellationToken); } } diff --git a/src/Microsoft.FeatureManagement/Targeting/TargetingFilter.cs b/src/Microsoft.FeatureManagement/Targeting/TargetingFilter.cs index f94a0463..93e753ef 100644 --- a/src/Microsoft.FeatureManagement/Targeting/TargetingFilter.cs +++ b/src/Microsoft.FeatureManagement/Targeting/TargetingFilter.cs @@ -49,7 +49,7 @@ public async Task EvaluateAsync(FeatureFilterEvaluationContext context, Ca // // Acquire targeting context via accessor - TargetingContext targetingContext = await _contextAccessor.GetContextAsync().ConfigureAwait(false); + TargetingContext targetingContext = await _contextAccessor.GetContextAsync(cancellationToken).ConfigureAwait(false); // // Ensure targeting can be performed diff --git a/tests/Tests.FeatureManagement/OnDemandTargetingContextAccessor.cs b/tests/Tests.FeatureManagement/OnDemandTargetingContextAccessor.cs index 7eb7e971..aaff4a41 100644 --- a/tests/Tests.FeatureManagement/OnDemandTargetingContextAccessor.cs +++ b/tests/Tests.FeatureManagement/OnDemandTargetingContextAccessor.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. // using Microsoft.FeatureManagement.FeatureFilters; +using System.Threading; using System.Threading.Tasks; namespace Tests.FeatureManagement @@ -10,7 +11,7 @@ class OnDemandTargetingContextAccessor : ITargetingContextAccessor { public TargetingContext Current { get; set; } - public ValueTask GetContextAsync() + public ValueTask GetContextAsync(CancellationToken _) { return new ValueTask(Current); }