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.
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
- mutation driven feature rollout
- policy checks around sensitive toggles
- batch execution with mixed outcomes
- history retrieval and log printing
- using
MutationContextmetadata for approval tracking
Program.csFeatureFlags.csprojState/FeatureFlagsState.csMutations/EnableFeatureMutation.csMutations/DisableFeatureMutation.csPolicies/BusinessHoursPolicy.csPolicies/RequireTwoManApprovalPolicy.csScenarios/EnableNewCheckoutScenario.csScenarios/DisableLegacyCheckoutScenario.csScenarios/BatchFeatureToggleScenario.cs
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.
EnableFeatureMutation enables a flag.
- validates that the feature name exists
- writes the new enabled value into copied state
- emits
ChangeSetentry for the feature
DisableFeatureMutation disables a flag.
- validates that the feature exists
- writes the new disabled value into copied state
- emits change record for the flag
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
BusinessHoursPolicy is simple time based policy for highrisk changes.
Use it as reference if you want to restrict rollout windows.
EnableNewCheckoutScenario shows how new feature is turned on from known starting state.
DisableLegacyCheckoutScenario shows how feature can be turned off with approval metadata attached.
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
Program.csState/FeatureFlagsState.csMutations/EnableFeatureMutation.csMutations/DisableFeatureMutation.csPolicies/RequireTwoManApprovalPolicy.csScenarios/BatchFeatureToggleScenario.cs
dotnet run --project Examples/Core/FeatureFlags/FeatureFlags.csprojYou 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.