Skip to content

Commit

Permalink
Merge pull request #514 from microsoft/main
Browse files Browse the repository at this point in the history
Merge main into release/v4 for 4.0.0 release
  • Loading branch information
rossgrambo authored Oct 31, 2024
2 parents e37277a + 2c94bdf commit 99b1bef
Show file tree
Hide file tree
Showing 17 changed files with 445 additions and 255 deletions.
7 changes: 7 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Why this PR?

-motivation for making this change-

## Visible Changes

-changes that are visible to developers using this library-
4 changes: 3 additions & 1 deletion build/install-dotnet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Channel 7.0

&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Channel 8.0
&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Channel 8.0

&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Channel 9.0
6 changes: 3 additions & 3 deletions examples/ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion examples/ConsoleApp/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
}
]
}
}
}
6 changes: 3 additions & 3 deletions examples/TargetingConsoleApp/TargetingConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public FeatureGateAttribute(RequirementType requirementType, params object[] fea
public RequirementType RequirementType { get; }

/// <summary>
/// Performs controller action pre-procesing to ensure that any or all of the specified features are enabled.
/// Performs controller action pre-processing to ensure that any or all of the specified features are enabled.
/// </summary>
/// <param name="context">The context of the MVC action.</param>
/// <param name="next">The action delegate.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Import Project="..\..\build\Versioning.props" />

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>..\..\build\Microsoft.FeatureManagement.snk</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace Microsoft.FeatureManagement.Mvc.TagHelpers
/// </summary>
public class FeatureTagHelper : TagHelper
{
private readonly IVariantFeatureManager _featureManager;
private readonly IFeatureManager _featureManager;
private readonly IVariantFeatureManager _variantFeatureManager;

/// <summary>
/// A feature name, or comma separated list of feature names, for which the content should be rendered. By default, all specified features must be enabled to render the content, but this requirement can be controlled by the <see cref="Requirement"/> property.
Expand All @@ -41,9 +42,12 @@ public class FeatureTagHelper : TagHelper
/// Creates a feature tag helper.
/// </summary>
/// <param name="featureManager">The feature manager snapshot to use to evaluate feature state.</param>
public FeatureTagHelper(IVariantFeatureManagerSnapshot featureManager)
/// <param name="variantFeatureManager">The variant feature manager snapshot to use to evaluate feature state.</param>
public FeatureTagHelper(IFeatureManagerSnapshot featureManager, IVariantFeatureManagerSnapshot variantFeatureManager)
{
// Takes both a feature manager and a variant feature manager for backwards compatibility.
_featureManager = featureManager ?? throw new ArgumentNullException(nameof(featureManager));
_variantFeatureManager = variantFeatureManager ?? throw new ArgumentNullException(nameof(variantFeatureManager));
}

/// <summary>
Expand Down Expand Up @@ -84,7 +88,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
enabled = await variants.Any(
async variant =>
{
Variant assignedVariant = await _featureManager.GetVariantAsync(features.First()).ConfigureAwait(false);
Variant assignedVariant = await _variantFeatureManager.GetVariantAsync(features.First()).ConfigureAwait(false);

return variant == assignedVariant?.Name;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public sealed class ConfigurationFeatureDefinitionProvider : IFeatureDefinitionP
// provider to be marked for caching as well.

private readonly IConfiguration _configuration;
private readonly ConcurrentDictionary<string, FeatureDefinition> _definitions;
private readonly ConcurrentDictionary<string, Task<FeatureDefinition>> _definitions;
private IDisposable _changeSubscription;
private int _stale = 0;
private readonly Func<string, Task<FeatureDefinition>> _getFeatureDefinitionFunc;

const string ParseValueErrorString = "Invalid setting '{0}' with value '{1}' for feature '{2}'.";

Expand All @@ -37,11 +38,16 @@ public sealed class ConfigurationFeatureDefinitionProvider : IFeatureDefinitionP
public ConfigurationFeatureDefinitionProvider(IConfiguration configuration)
{
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
_definitions = new ConcurrentDictionary<string, FeatureDefinition>();
_definitions = new ConcurrentDictionary<string, Task<FeatureDefinition>>();

_changeSubscription = ChangeToken.OnChange(
() => _configuration.GetReloadToken(),
() => _stale = 1);

_getFeatureDefinitionFunc = (featureName) =>
{
return Task.FromResult(GetMicrosoftSchemaFeatureDefinition(featureName) ?? GetDotnetSchemaFeatureDefinition(featureName));
};
}

/// <summary>
Expand Down Expand Up @@ -86,10 +92,7 @@ public Task<FeatureDefinition> GetFeatureDefinitionAsync(string featureName)
_definitions.Clear();
}

return Task.FromResult(
_definitions.GetOrAdd(
featureName,
(_) => GetMicrosoftSchemaFeatureDefinition(featureName) ?? GetDotnetSchemaFeatureDefinition(featureName)));
return _definitions.GetOrAdd(featureName, _getFeatureDefinitionFunc);
}

/// <summary>
Expand All @@ -98,7 +101,7 @@ public Task<FeatureDefinition> GetFeatureDefinitionAsync(string featureName)
/// <returns>An enumerator which provides asynchronous iteration over feature definitions.</returns>
//
// The async key word is necessary for creating IAsyncEnumerable.
// The need to disable this warning occurs when implementaing async stream synchronously.
// The need to disable this warning occurs when implementing async stream synchronously.
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public async IAsyncEnumerable<FeatureDefinition> GetAllFeatureDefinitionsAsync()
#pragma warning restore CS1998
Expand All @@ -121,7 +124,7 @@ public async IAsyncEnumerable<FeatureDefinition> GetAllFeatureDefinitionsAsync()

//
// Underlying IConfigurationSection data is dynamic so latest feature definitions are returned
FeatureDefinition definition = _definitions.GetOrAdd(featureName, (_) => ParseMicrosoftSchemaFeatureDefinition(featureSection));
FeatureDefinition definition = _definitions.GetOrAdd(featureName, _getFeatureDefinitionFunc).Result;

if (definition != null)
{
Expand All @@ -142,7 +145,7 @@ public async IAsyncEnumerable<FeatureDefinition> GetAllFeatureDefinitionsAsync()

//
// Underlying IConfigurationSection data is dynamic so latest feature definitions are returned
FeatureDefinition definition = _definitions.GetOrAdd(featureName, (_) => ParseDotnetSchemaFeatureDefinition(featureSection));
FeatureDefinition definition = _definitions.GetOrAdd(featureName, _getFeatureDefinitionFunc).Result;

if (definition != null)
{
Expand All @@ -155,32 +158,32 @@ private FeatureDefinition GetDotnetSchemaFeatureDefinition(string featureName)
{
IEnumerable<IConfigurationSection> dotnetFeatureDefinitionSections = GetDotnetFeatureDefinitionSections();

IConfigurationSection configuration = dotnetFeatureDefinitionSections
IConfigurationSection dotnetFeatureDefinitionConfiguration = dotnetFeatureDefinitionSections
.FirstOrDefault(section =>
string.Equals(section.Key, featureName, StringComparison.OrdinalIgnoreCase));

if (configuration == null)
if (dotnetFeatureDefinitionConfiguration == null)
{
return null;
}

return ParseDotnetSchemaFeatureDefinition(configuration);
return ParseDotnetSchemaFeatureDefinition(dotnetFeatureDefinitionConfiguration);
}

private FeatureDefinition GetMicrosoftSchemaFeatureDefinition(string featureName)
{
IEnumerable<IConfigurationSection> microsoftFeatureDefinitionSections = GetMicrosoftFeatureDefinitionSections();

IConfigurationSection configuration = microsoftFeatureDefinitionSections
IConfigurationSection microsoftFeatureDefinitionConfiguration = microsoftFeatureDefinitionSections
.LastOrDefault(section =>
string.Equals(section[MicrosoftFeatureManagementFields.Id], featureName, StringComparison.OrdinalIgnoreCase));

if (configuration == null)
if (microsoftFeatureDefinitionConfiguration == null)
{
return null;
}

return ParseMicrosoftSchemaFeatureDefinition(configuration);
return ParseMicrosoftSchemaFeatureDefinition(microsoftFeatureDefinitionConfiguration);
}

private IEnumerable<IConfigurationSection> GetDotnetFeatureDefinitionSections()
Expand Down Expand Up @@ -518,7 +521,7 @@ private FeatureDefinition ParseMicrosoftSchemaFeatureDefinition(IConfigurationSe
};
}

private T ParseEnum<T>(string feature, string rawValue, string fieldKeyword)
private static T ParseEnum<T>(string feature, string rawValue, string fieldKeyword)
where T : struct, Enum
{
Debug.Assert(!string.IsNullOrEmpty(rawValue));
Expand All @@ -533,7 +536,7 @@ private T ParseEnum<T>(string feature, string rawValue, string fieldKeyword)
return value;
}

private double ParseDouble(string feature, string rawValue, string fieldKeyword)
private static double ParseDouble(string feature, string rawValue, string fieldKeyword)
{
Debug.Assert(!string.IsNullOrEmpty(rawValue));

Expand All @@ -547,7 +550,7 @@ private double ParseDouble(string feature, string rawValue, string fieldKeyword)
return value;
}

private bool ParseBool(string feature, string rawValue, string fieldKeyword)
private static bool ParseBool(string feature, string rawValue, string fieldKeyword)
{
Debug.Assert(!string.IsNullOrEmpty(rawValue));

Expand Down
Loading

0 comments on commit 99b1bef

Please sign in to comment.