FeatureFlags
This example shows how to treat feature flags as first class state mutations with auditability, history inspection, and approval style restrictions.
It is good fit when you want to see how the engine behaves in an operational workflow where toggles may be simple, but the decision process around them is not.
Domain
The state is dictionary of feature names to enabled or disabled values.
The example covers three workflows:
- enabling feature
- disabling feature
- toggling multiple features in batch
What this example demonstrates
- mutation driven feature rollout
- policy checks around sensitive toggles
- batch execution with mixed outcomes
- history retrieval and log printing
- using
MutationContextmetadata for approval tracking
Project structure
Program.csFeatureFlags.csprojState/FeatureFlagsState.csMutations/EnableFeatureMutation.csMutations/DisableFeatureMutation.csPolicies/BusinessHoursPolicy.csPolicies/RequireTwoManApprovalPolicy.csScenarios/EnableNewCheckoutScenario.csScenarios/DisableLegacyCheckoutScenario.csScenarios/BatchFeatureToggleScenario.cs
How it works
Program.cs:
- registers the engine with strict options
- resolves
IMutationEngine - registers
RequireTwoManApprovalPolicy - runs the example scenarios
- prints history for the main state
- prints engine statistics
The sample also includes BusinessHoursPolicy as reference implementation. It is not registered by default, but it shows how time based operational limits would be expressed.
Mutation flow
Enable feature
EnableFeatureMutation enables a flag.
- validates that the feature name exists
- writes the new enabled value into copied state
- emits
ChangeSetentry for the feature
Disable feature
DisableFeatureMutation disables a flag.
- validates that the feature exists
- writes the new disabled value into copied state
- emits change record for the flag
Policies
Two man approval
RequireTwoManApprovalPolicy blocks certain high risk feature changes unless metadata contains two distinct approvers.
It demonstrates:
- inspection of
MutationContext.Metadata - policy decisions based on the mutation type
- excluding the actor from the approval list
Business hours
BusinessHoursPolicy is simple time based policy for highrisk changes.
Use it as reference if you want to restrict rollout windows.
Scenarios
Enable new checkout
EnableNewCheckoutScenario shows how new feature is turned on from known starting state.
Disable legacy checkout
DisableLegacyCheckoutScenario shows how feature can be turned off with approval metadata attached.
Batch feature toggle
BatchFeatureToggleScenario shows mixed feature operations in single batch.
It demonstrates:
- batch mutation submission
- partial success and failure handling
- result logging
- folding the batch output back into the final state
What to read first
Program.csState/FeatureFlagsState.csMutations/EnableFeatureMutation.csMutations/DisableFeatureMutation.csPolicies/RequireTwoManApprovalPolicy.csScenarios/BatchFeatureToggleScenario.cs
Run
dotnet run --project Examples/Core/FeatureFlags/FeatureFlags.csproj
Expected output
You should see:
- one or more feature flag changes
- batch mutation logs
- a history dump for the tracked state
- a statistics summary at the end
The sample is intentionally written as an operational console app, not as presentation layer.