Skip to content

GetFeatureNames can return duplicates #534

@benmccallum

Description

@benmccallum

In experimenting with transitioning to the MS feat mgmt schema, I added configuration for it under feature_management (alongside existing configuration under FeatureManagement).

In doing so, I noticed that GetFeatureNamesAsync returned the name of that feature multiple times. That actually broke this code we had in one of our apps which surfaces all the flags in one go to an old UI:

var featureNamesEnumerable = _featureManager.GetFeatureNamesAsync();
await featureNamesEnumerable.ForEachAwaitAsync(async featureName =>
{
    var isEnabled = await _featureManager.IsEnabledAsync(featureName);
    featureFlags.Add(featureName, isEnabled);
});

(note, needs System.Linq.Async nuget package).

Given that IsEnabledAsync digs into the provider and checks for MS Feature Mgmt schema config first, before falling back to the .NET Feature Mgmt schema config after, i.e. it doesn't matter that there's dupe config, it supports this, it feels a bit unexpected to see the feature name appear twice. Easy fix is:

var featureNamesEnumerable = _featureManager.GetFeatureNamesAsync().Distinct();
// ...

But wondering if it's worth doing that in the GetFeatureNamesAsync implementation? Happy to submit a PR if that's approved, as I also need to submit my other PR for the MVC tag helper and can knock both PRs out in one go.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions