From 6c50f043102a4a11da465515bef46fb97ceb8c81 Mon Sep 17 00:00:00 2001 From: Jimmy Campbell Date: Mon, 20 Sep 2021 13:31:59 -0400 Subject: [PATCH] Revert "Add the capability to prevent features with feature filters from being evaluated. (#143)" This reverts commit 4231727e6834c301b0dcfa658e43830534ecaf78. --- .../ConfigurationFeatureDefinitionProvider.cs | 14 +----------- .../FeatureDefinition.cs | 6 ----- .../FeatureManagementError.cs | 7 +----- .../FeatureManager.cs | 5 ++--- .../FeatureManagement.cs | 22 ------------------- .../Tests.FeatureManagement/appsettings.json | 15 ------------- 6 files changed, 4 insertions(+), 65 deletions(-) diff --git a/src/Microsoft.FeatureManagement/ConfigurationFeatureDefinitionProvider.cs b/src/Microsoft.FeatureManagement/ConfigurationFeatureDefinitionProvider.cs index 44fea504..8763b850 100644 --- a/src/Microsoft.FeatureManagement/ConfigurationFeatureDefinitionProvider.cs +++ b/src/Microsoft.FeatureManagement/ConfigurationFeatureDefinitionProvider.cs @@ -167,22 +167,10 @@ We support } } - bool evaluate = true; - - val = configurationSection[nameof(FeatureDefinition.Evaluate)]; - - if (!string.IsNullOrEmpty(val) && !bool.TryParse(val, out evaluate)) - { - throw new FeatureManagementException( - FeatureManagementError.InvalidConfiguration, - $"The feature '{configurationSection.Key}' has an invalid value for the '{nameof(FeatureDefinition.Evaluate)}' property."); - } - return new FeatureDefinition() { Name = configurationSection.Key, - EnabledFor = enabledFor, - Evaluate = evaluate + EnabledFor = enabledFor }; } diff --git a/src/Microsoft.FeatureManagement/FeatureDefinition.cs b/src/Microsoft.FeatureManagement/FeatureDefinition.cs index de02d2fb..4931fd5b 100644 --- a/src/Microsoft.FeatureManagement/FeatureDefinition.cs +++ b/src/Microsoft.FeatureManagement/FeatureDefinition.cs @@ -19,11 +19,5 @@ public class FeatureDefinition /// The feature filters that the feature can be enabled for. /// public IEnumerable EnabledFor { get; set; } = new List(); - - /// - /// Dictates whether the feature should be evaluated. If false, the feature will be considered disabled. - /// The default value is true. - /// - public bool Evaluate { get; set; } = true; } } diff --git a/src/Microsoft.FeatureManagement/FeatureManagementError.cs b/src/Microsoft.FeatureManagement/FeatureManagementError.cs index 8b3f84bd..1cdb9eed 100644 --- a/src/Microsoft.FeatureManagement/FeatureManagementError.cs +++ b/src/Microsoft.FeatureManagement/FeatureManagementError.cs @@ -21,11 +21,6 @@ public enum FeatureManagementError /// /// A feature that was requested for evaluation was not found. /// - MissingFeature, - - /// - /// An invalid configuration was encountered when performing a feature management operation. - /// - InvalidConfiguration + MissingFeature } } diff --git a/src/Microsoft.FeatureManagement/FeatureManager.cs b/src/Microsoft.FeatureManagement/FeatureManager.cs index 4aad0a52..097af3a2 100644 --- a/src/Microsoft.FeatureManagement/FeatureManager.cs +++ b/src/Microsoft.FeatureManagement/FeatureManager.cs @@ -74,8 +74,7 @@ private async Task IsEnabledAsync(string feature, TContext appCo FeatureDefinition featureDefinition = await _featureDefinitionProvider.GetFeatureDefinitionAsync(feature).ConfigureAwait(false); - if (featureDefinition != null - && featureDefinition.Evaluate) + if (featureDefinition != null) { // // Check if feature is always on @@ -142,7 +141,7 @@ private async Task IsEnabledAsync(string feature, TContext appCo } } } - else if (featureDefinition == null) + else { string errorMessage = $"The feature declaration for the feature '{feature}' was not found."; diff --git a/tests/Tests.FeatureManagement/FeatureManagement.cs b/tests/Tests.FeatureManagement/FeatureManagement.cs index a0caa6b9..2dade89c 100644 --- a/tests/Tests.FeatureManagement/FeatureManagement.cs +++ b/tests/Tests.FeatureManagement/FeatureManagement.cs @@ -26,8 +26,6 @@ public class FeatureManagement private const string OffFeature = "OffFeature"; private const string ConditionalFeature = "ConditionalFeature"; private const string ContextualFeature = "ContextualFeature"; - private const string AlwaysOnFeature = "AlwaysOnFeature"; - private const string NonEvaluatedAlwaysOnFeature = "NonEvaluatedAlwaysOnFeature"; [Fact] public async Task ReadsConfiguration() @@ -617,26 +615,6 @@ public async Task ThreadsafeSnapshot() } } - [Fact] - public async Task TogglesEvaluation() - { - IConfiguration config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); - - var services = new ServiceCollection(); - - services - .AddSingleton(config) - .AddFeatureManagement(); - - ServiceProvider serviceProvider = services.BuildServiceProvider(); - - IFeatureManager featureManager = serviceProvider.GetRequiredService(); - - Assert.True(await featureManager.IsEnabledAsync(AlwaysOnFeature)); - - Assert.False(await featureManager.IsEnabledAsync(NonEvaluatedAlwaysOnFeature)); - } - private static void DisableEndpointRouting(MvcOptions options) { #if NET5_0 || NETCOREAPP3_1 diff --git a/tests/Tests.FeatureManagement/appsettings.json b/tests/Tests.FeatureManagement/appsettings.json index 0bfad5d4..f033a400 100644 --- a/tests/Tests.FeatureManagement/appsettings.json +++ b/tests/Tests.FeatureManagement/appsettings.json @@ -63,21 +63,6 @@ } } ] - }, - "AlwaysOnFeature": { - "EnabledFor": [ - { - "Name": "AlwaysOn" - } - ] - }, - "NonEvaluatedAlwaysOnFeature": { - "Evaluate": false, - "EnabledFor": [ - { - "Name": "AlwaysOn" - } - ] } } }