Skip to content

Commit c1451d3

Browse files
committed
Revert "Revert "Add cancellation token parameter to async feature management interfaces. (#131)" (#139)"
This reverts commit e531863.
1 parent d28bf88 commit c1451d3

32 files changed

+144
-89
lines changed

examples/ConsoleApp/FeatureFilters/AccountIdFilter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.FeatureManagement;
77
using System;
88
using System.Collections.Generic;
9+
using System.Threading;
910
using System.Threading.Tasks;
1011

1112
namespace Consoto.Banking.AccountService.FeatureManagement
@@ -17,7 +18,7 @@ namespace Consoto.Banking.AccountService.FeatureManagement
1718
[FilterAlias("AccountId")]
1819
class AccountIdFilter : IContextualFeatureFilter<IAccountContext>
1920
{
20-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureEvaluationContext, IAccountContext accountContext)
21+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureEvaluationContext, IAccountContext accountContext, CancellationToken _)
2122
{
2223
if (string.IsNullOrEmpty(accountContext?.AccountId))
2324
{

examples/ConsoleApp/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.FeatureManagement.FeatureFilters;
99
using System;
1010
using System.Collections.Generic;
11+
using System.Threading;
1112
using System.Threading.Tasks;
1213

1314
namespace Consoto.Banking.AccountService
@@ -58,7 +59,7 @@ public static async Task Main(string[] args)
5859
AccountId = account
5960
};
6061

61-
bool enabled = await featureManager.IsEnabledAsync(FeatureName, accountServiceContext);
62+
bool enabled = await featureManager.IsEnabledAsync(FeatureName, accountServiceContext, CancellationToken.None);
6263

6364
//
6465
// Output results

examples/FeatureFlagDemo/BrowserFilter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.FeatureManagement;
77
using System;
88
using System.Linq;
9+
using System.Threading;
910
using System.Threading.Tasks;
1011

1112
namespace FeatureFlagDemo.FeatureManagement.FeatureFilters
@@ -23,7 +24,7 @@ public BrowserFilter(IHttpContextAccessor httpContextAccessor)
2324
_httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
2425
}
2526

26-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context)
27+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, CancellationToken _)
2728
{
2829
BrowserFilterSettings settings = context.Parameters.Get<BrowserFilterSettings>() ?? new BrowserFilterSettings();
2930

examples/FeatureFlagDemo/Controllers/HomeController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.FeatureManagement;
99
using Microsoft.FeatureManagement.Mvc;
1010
using System.Threading.Tasks;
11+
using System.Threading;
1112

1213
namespace FeatureFlagDemo.Controllers
1314
{
@@ -26,11 +27,11 @@ public IActionResult Index()
2627
return View();
2728
}
2829

29-
public async Task<IActionResult> About()
30+
public async Task<IActionResult> About(CancellationToken cancellationToken)
3031
{
3132
ViewData["Message"] = "Your application description page.";
3233

33-
if (await _featureManager.IsEnabledAsync(nameof(MyFeatureFlags.CustomViewData)))
34+
if (await _featureManager.IsEnabledAsync(nameof(MyFeatureFlags.CustomViewData), cancellationToken))
3435
{
3536
ViewData["Message"] = $"This is FANCY CONTENT you can see only if '{nameof(MyFeatureFlags.CustomViewData)}' is enabled.";
3637
};

examples/FeatureFlagDemo/HttpContextTargetingContextAccessor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Collections.Generic;
88
using System.Security.Claims;
9+
using System.Threading;
910
using System.Threading.Tasks;
1011

1112
namespace FeatureFlagDemo
@@ -23,7 +24,7 @@ public HttpContextTargetingContextAccessor(IHttpContextAccessor httpContextAcces
2324
_httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
2425
}
2526

26-
public ValueTask<TargetingContext> GetContextAsync()
27+
public ValueTask<TargetingContext> GetContextAsync(CancellationToken _)
2728
{
2829
HttpContext httpContext = _httpContextAccessor.HttpContext;
2930

examples/FeatureFlagDemo/SuperUserFilter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
// Licensed under the MIT license.
33
//
44
using Microsoft.FeatureManagement;
5+
using System.Threading;
56
using System.Threading.Tasks;
67

78
namespace FeatureFlagDemo.FeatureManagement.FeatureFilters
89
{
910
public class SuperUserFilter : IFeatureFilter
1011
{
11-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context)
12+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, CancellationToken _)
1213
{
1314
return Task.FromResult(false);
1415
}

examples/TargetingConsoleApp/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System;
1010
using System.Collections.Generic;
1111
using System.Linq;
12+
using System.Threading;
1213
using System.Threading.Tasks;
1314

1415
namespace Consoto.Banking.HelpDesk
@@ -62,7 +63,7 @@ public static async Task Main(string[] args)
6263
Groups = user.Groups
6364
};
6465

65-
bool enabled = await featureManager.IsEnabledAsync(FeatureName, targetingContext);
66+
bool enabled = await featureManager.IsEnabledAsync(FeatureName, targetingContext, CancellationToken.None);
6667

6768
//
6869
// Output results

src/Microsoft.FeatureManagement.AspNetCore/FeatureGateAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public override async Task OnActionExecutionAsync(ActionExecutingContext context
107107
//
108108
// Enabled state is determined by either 'any' or 'all' features being enabled.
109109
bool enabled = RequirementType == RequirementType.All ?
110-
await Features.All(async feature => await fm.IsEnabledAsync(feature).ConfigureAwait(false)) :
111-
await Features.Any(async feature => await fm.IsEnabledAsync(feature).ConfigureAwait(false));
110+
await Features.All(async feature => await fm.IsEnabledAsync(feature, context.HttpContext.RequestAborted).ConfigureAwait(false)).ConfigureAwait(false) :
111+
await Features.Any(async feature => await fm.IsEnabledAsync(feature, context.HttpContext.RequestAborted).ConfigureAwait(false)).ConfigureAwait(false);
112112

113113
if (enabled)
114114
{

src/Microsoft.FeatureManagement.AspNetCore/FeatureGatedAsyncActionFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE
3030
{
3131
IFeatureManager featureManager = context.HttpContext.RequestServices.GetRequiredService<IFeatureManagerSnapshot>();
3232

33-
if (await featureManager.IsEnabledAsync(FeatureName).ConfigureAwait(false))
33+
if (await featureManager.IsEnabledAsync(FeatureName, context.HttpContext.RequestAborted).ConfigureAwait(false))
3434
{
3535
IServiceProvider serviceProvider = context.HttpContext.RequestServices.GetRequiredService<IServiceProvider>();
3636

src/Microsoft.FeatureManagement.AspNetCore/TagHelpers/FeatureTagHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.AspNetCore.Razor.TagHelpers;
55
using System.Collections.Generic;
66
using System.Linq;
7+
using System.Threading;
78
using System.Threading.Tasks;
89

910
namespace Microsoft.FeatureManagement.Mvc.TagHelpers
@@ -55,8 +56,8 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
5556
IEnumerable<string> names = Name.Split(',').Select(n => n.Trim());
5657

5758
enabled = Requirement == RequirementType.All ?
58-
await names.All(async n => await _featureManager.IsEnabledAsync(n).ConfigureAwait(false)) :
59-
await names.Any(async n => await _featureManager.IsEnabledAsync(n).ConfigureAwait(false));
59+
await names.All(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false) :
60+
await names.Any(async n => await _featureManager.IsEnabledAsync(n, CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false);
6061
}
6162

6263
if (Negate)

0 commit comments

Comments
 (0)