Skip to content

How to programmatically create an “always enabled” FeatureDefinition? #576

@ShayMusachanov-dev

Description

@ShayMusachanov-dev

I’m implementing a custom IFeatureDefinitionProvider that reads features from a database or an HTTP service instead of JSON configuration. My goal is to represent a feature that is always enabled, equivalent to this JSON:

"FeatureA": {
    "enabled": true
}

Looking at the source (ConfigurationFeatureDefinitionProvider.ParseMicrosoftSchemaFeatureDefinition), the library seems to convert such JSON into a FeatureDefinition with:

  • Status = FeatureStatus.Conditional
  • EnabledFor containing a single FeatureFilterConfiguration with Name = "AlwaysOn"

Example based on my understanding:

var featureEnabled = new FeatureDefinition
{
    Name = "FeatureA",
    EnabledFor = new List<FeatureFilterConfiguration>
    {
        new FeatureFilterConfiguration { Name = "AlwaysOn" }
    },
    Status = FeatureStatus.Conditional
};

My questions:

  1. Is this the correct/recommended way to create a feature that is always enabled without defining any conditions?
  2. Is there an official API or helper for this, so I don’t have to replicate the logic from ConfigurationFeatureDefinitionProvider?
  3. Are there any docs explaining this behavior?

I want to make sure my IFeatureDefinitionProvider correctly handles “always enabled” features without relying on JSON files.

Thanks!

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