Skip to content

Commit d087e7b

Browse files
committed
Revert "Revert "Added default value for cancellation token in interfaces to keep existing usage possible. (#133)" (#138)"
This reverts commit 8f9a7e4.
1 parent c1451d3 commit d087e7b

17 files changed

+27
-27
lines changed

examples/ConsoleApp/FeatureFilters/AccountIdFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Consoto.Banking.AccountService.FeatureManagement
1818
[FilterAlias("AccountId")]
1919
class AccountIdFilter : IContextualFeatureFilter<IAccountContext>
2020
{
21-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureEvaluationContext, IAccountContext accountContext, CancellationToken _)
21+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureEvaluationContext, IAccountContext accountContext, CancellationToken cancellationToken)
2222
{
2323
if (string.IsNullOrEmpty(accountContext?.AccountId))
2424
{

examples/FeatureFlagDemo/BrowserFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public BrowserFilter(IHttpContextAccessor httpContextAccessor)
2424
_httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
2525
}
2626

27-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, CancellationToken _)
27+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, CancellationToken cancellationToken)
2828
{
2929
BrowserFilterSettings settings = context.Parameters.Get<BrowserFilterSettings>() ?? new BrowserFilterSettings();
3030

examples/FeatureFlagDemo/HttpContextTargetingContextAccessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public HttpContextTargetingContextAccessor(IHttpContextAccessor httpContextAcces
2424
_httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
2525
}
2626

27-
public ValueTask<TargetingContext> GetContextAsync(CancellationToken _)
27+
public ValueTask<TargetingContext> GetContextAsync(CancellationToken cancellationToken)
2828
{
2929
HttpContext httpContext = _httpContextAccessor.HttpContext;
3030

examples/FeatureFlagDemo/SuperUserFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace FeatureFlagDemo.FeatureManagement.FeatureFilters
99
{
1010
public class SuperUserFilter : IFeatureFilter
1111
{
12-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, CancellationToken _)
12+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, CancellationToken cancellationToken)
1313
{
1414
return Task.FromResult(false);
1515
}

src/Microsoft.FeatureManagement/ConfigurationFeatureDefinitionProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void Dispose()
4646
_changeSubscription = null;
4747
}
4848

49-
public Task<FeatureDefinition> GetFeatureDefinitionAsync(string featureName, CancellationToken _)
49+
public Task<FeatureDefinition> GetFeatureDefinitionAsync(string featureName, CancellationToken cancellationToken)
5050
{
5151
if (featureName == null)
5252
{
@@ -69,7 +69,7 @@ public Task<FeatureDefinition> GetFeatureDefinitionAsync(string featureName, Can
6969
// The async key word is necessary for creating IAsyncEnumerable.
7070
// The need to disable this warning occurs when implementaing async stream synchronously.
7171
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
72-
public async IAsyncEnumerable<FeatureDefinition> GetAllFeatureDefinitionsAsync([EnumeratorCancellation] CancellationToken _)
72+
public async IAsyncEnumerable<FeatureDefinition> GetAllFeatureDefinitionsAsync([EnumeratorCancellation] CancellationToken cancellationToken)
7373
#pragma warning restore CS1998
7474
{
7575
if (Interlocked.Exchange(ref _stale, 0) != 0)

src/Microsoft.FeatureManagement/EmptySessionManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ namespace Microsoft.FeatureManagement
1111
/// </summary>
1212
class EmptySessionManager : ISessionManager
1313
{
14-
public Task SetAsync(string featureName, bool enabled, CancellationToken _)
14+
public Task SetAsync(string featureName, bool enabled, CancellationToken cancellationToken)
1515
{
1616
return Task.CompletedTask;
1717
}
1818

19-
public Task<bool?> GetAsync(string featureName, CancellationToken _)
19+
public Task<bool?> GetAsync(string featureName, CancellationToken cancellationToken)
2020
{
2121
return Task.FromResult((bool?)null);
2222
}

src/Microsoft.FeatureManagement/IContextualFeatureFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public interface IContextualFeatureFilter<TContext> : IFeatureFilterMetadata
2121
/// <param name="appContext">A context defined by the application that is passed in to the feature management system to provide contextual information for evaluating a feature's state.</param>
2222
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
2323
/// <returns>True if the filter's criteria has been met, false otherwise.</returns>
24-
Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureFilterContext, TContext appContext, CancellationToken cancellationToken);
24+
Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureFilterContext, TContext appContext, CancellationToken cancellationToken = default);
2525
}
2626
}

src/Microsoft.FeatureManagement/IFeatureDefinitionProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ public interface IFeatureDefinitionProvider
1818
/// <param name="featureName">The name of the feature to retrieve the definition for.</param>
1919
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
2020
/// <returns>The feature's definition.</returns>
21-
Task<FeatureDefinition> GetFeatureDefinitionAsync(string featureName, CancellationToken cancellationToken);
21+
Task<FeatureDefinition> GetFeatureDefinitionAsync(string featureName, CancellationToken cancellationToken = default);
2222

2323
/// <summary>
2424
/// Retrieves definitions for all features.
2525
/// </summary>
2626
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
2727
/// <returns>An enumerator which provides asynchronous iteration over feature definitions.</returns>
28-
IAsyncEnumerable<FeatureDefinition> GetAllFeatureDefinitionsAsync(CancellationToken cancellationToken);
28+
IAsyncEnumerable<FeatureDefinition> GetAllFeatureDefinitionsAsync(CancellationToken cancellationToken = default);
2929
}
3030
}

src/Microsoft.FeatureManagement/IFeatureFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public interface IFeatureFilter : IFeatureFilterMetadata
1717
/// <param name="context">A feature filter evaluation context that contains information that may be needed to evaluate the filter. This context includes configuration, if any, for this filter for the feature being evaluated.</param>
1818
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
1919
/// <returns>True if the filter's criteria has been met, false otherwise.</returns>
20-
Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, CancellationToken cancellationToken);
20+
Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, CancellationToken cancellationToken = default);
2121
}
2222
}

src/Microsoft.FeatureManagement/IFeatureManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public interface IFeatureManager
1717
/// </summary>
1818
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
1919
/// <returns>An enumerator which provides asynchronous iteration over the feature names registered in the feature manager.</returns>
20-
IAsyncEnumerable<string> GetFeatureNamesAsync(CancellationToken cancellationToken);
20+
IAsyncEnumerable<string> GetFeatureNamesAsync(CancellationToken cancellationToken = default);
2121

2222
/// <summary>
2323
/// Checks whether a given feature is enabled.
2424
/// </summary>
2525
/// <param name="feature">The name of the feature to check.</param>
2626
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
2727
/// <returns>True if the feature is enabled, otherwise false.</returns>
28-
Task<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken);
28+
Task<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken = default);
2929

3030
/// <summary>
3131
/// Checks whether a given feature is enabled.
@@ -34,6 +34,6 @@ public interface IFeatureManager
3434
/// <param name="context">A context providing information that can be used to evaluate whether a feature should be on or off.</param>
3535
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
3636
/// <returns>True if the feature is enabled, otherwise false.</returns>
37-
Task<bool> IsEnabledAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken);
37+
Task<bool> IsEnabledAsync<TContext>(string feature, TContext context, CancellationToken cancellationToken = default);
3838
}
3939
}

src/Microsoft.FeatureManagement/ISessionManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public interface ISessionManager
1717
/// <param name="featureName">The name of the feature.</param>
1818
/// <param name="enabled">The state of the feature.</param>
1919
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
20-
Task SetAsync(string featureName, bool enabled, CancellationToken cancellationToken);
20+
Task SetAsync(string featureName, bool enabled, CancellationToken cancellationToken = default);
2121

2222
/// <summary>
2323
/// Queries the session manager for the session's feature state, if any, for the given feature.
2424
/// </summary>
2525
/// <param name="featureName">The name of the feature.</param>
2626
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
2727
/// <returns>The state of the feature if it is present in the session, otherwise null.</returns>
28-
Task<bool?> GetAsync(string featureName, CancellationToken cancellationToken);
28+
Task<bool?> GetAsync(string featureName, CancellationToken cancellationToken = default);
2929
}
3030
}

src/Microsoft.FeatureManagement/Targeting/ITargetingContextAccessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ public interface ITargetingContextAccessor
1616
/// </summary>
1717
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>
1818
/// <returns>The current targeting context.</returns>
19-
ValueTask<TargetingContext> GetContextAsync(CancellationToken cancellationToken);
19+
ValueTask<TargetingContext> GetContextAsync(CancellationToken cancellationToken = default);
2020
}
2121
}

tests/Tests.FeatureManagement/ContextualTestFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ContextualTestFilter : IContextualFeatureFilter<IAccountContext>
1212
{
1313
public Func<FeatureFilterEvaluationContext, IAccountContext, bool> ContextualCallback { get; set; }
1414

15-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, IAccountContext accountContext, CancellationToken _)
15+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, IAccountContext accountContext, CancellationToken cancellationToken)
1616
{
1717
return Task.FromResult(ContextualCallback?.Invoke(context, accountContext) ?? false);
1818
}

tests/Tests.FeatureManagement/InMemoryFeatureDefinitionProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public InMemoryFeatureDefinitionProvider(IEnumerable<FeatureDefinition> featureD
1818
}
1919

2020
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
21-
public async IAsyncEnumerable<FeatureDefinition> GetAllFeatureDefinitionsAsync([EnumeratorCancellation] CancellationToken _)
21+
public async IAsyncEnumerable<FeatureDefinition> GetAllFeatureDefinitionsAsync([EnumeratorCancellation] CancellationToken cancellationToken)
2222
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
2323
{
2424
foreach (FeatureDefinition definition in _definitions)
@@ -27,7 +27,7 @@ public async IAsyncEnumerable<FeatureDefinition> GetAllFeatureDefinitionsAsync([
2727
}
2828
}
2929

30-
public Task<FeatureDefinition> GetFeatureDefinitionAsync(string featureName, CancellationToken _)
30+
public Task<FeatureDefinition> GetFeatureDefinitionAsync(string featureName, CancellationToken cancellationToken)
3131
{
3232
return Task.FromResult(_definitions.FirstOrDefault(definitions => definitions.Name.Equals(featureName, StringComparison.OrdinalIgnoreCase)));
3333
}

tests/Tests.FeatureManagement/InvalidFeatureFilter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ namespace Tests.FeatureManagement
1111
// Cannot implement more than one IFeatureFilter interface
1212
class InvalidFeatureFilter : IContextualFeatureFilter<IAccountContext>, IContextualFeatureFilter<object>
1313
{
14-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, IAccountContext accountContext, CancellationToken _)
14+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, IAccountContext accountContext, CancellationToken cancellationToken)
1515
{
1616
return Task.FromResult(false);
1717
}
1818

19-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureFilterContext, object appContext, CancellationToken _)
19+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureFilterContext, object appContext, CancellationToken cancellationToken)
2020
{
2121
return Task.FromResult(false);
2222
}
@@ -26,12 +26,12 @@ public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureFilterCont
2626
// Cannot implement more than one IFeatureFilter interface
2727
class InvalidFeatureFilter2 : IFeatureFilter, IContextualFeatureFilter<object>
2828
{
29-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureFilterContext, object appContext, CancellationToken _)
29+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureFilterContext, object appContext, CancellationToken cancellationToken)
3030
{
3131
return Task.FromResult(false);
3232
}
3333

34-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, CancellationToken _)
34+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, CancellationToken cancellationToken)
3535
{
3636
return Task.FromResult(false);
3737
}

tests/Tests.FeatureManagement/OnDemandTargetingContextAccessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class OnDemandTargetingContextAccessor : ITargetingContextAccessor
1111
{
1212
public TargetingContext Current { get; set; }
1313

14-
public ValueTask<TargetingContext> GetContextAsync(CancellationToken _)
14+
public ValueTask<TargetingContext> GetContextAsync(CancellationToken cancellationToken)
1515
{
1616
return new ValueTask<TargetingContext>(Current);
1717
}

tests/Tests.FeatureManagement/TestFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public object BindParameters(IConfiguration parameters)
2525
return parameters;
2626
}
2727

28-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, CancellationToken _)
28+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context, CancellationToken cancellationToken)
2929
{
3030
return Callback?.Invoke(context) ?? Task.FromResult(false);
3131
}

0 commit comments

Comments
 (0)