namespace StellaOps.FeatureFlags; /// /// Provider that supplies feature flag values from a specific source. /// Providers are ordered by priority in the composite service. /// public interface IFeatureFlagProvider { /// /// Unique name identifying this provider. /// string Name { get; } /// /// Priority order (lower = higher priority, checked first). /// int Priority { get; } /// /// Whether this provider supports watching for changes. /// bool SupportsWatch { get; } /// /// Tries to get the value of a feature flag. /// /// The feature flag key. /// Evaluation context for targeting. /// Cancellation token. /// The flag result, or null if this provider doesn't have the flag. Task TryGetFlagAsync( string flagKey, FeatureFlagEvaluationContext context, CancellationToken ct = default); /// /// Lists all feature flags known to this provider. /// /// Cancellation token. /// All flag definitions from this provider. Task> ListFlagsAsync(CancellationToken ct = default); /// /// Watches for changes to feature flags. /// Only called if SupportsWatch is true. /// /// Cancellation token. /// Stream of change events. IAsyncEnumerable WatchAsync(CancellationToken ct = default); } /// /// Base class for feature flag providers with common functionality. /// public abstract class FeatureFlagProviderBase : IFeatureFlagProvider { /// public abstract string Name { get; } /// public virtual int Priority => 100; /// public virtual bool SupportsWatch => false; /// public abstract Task TryGetFlagAsync( string flagKey, FeatureFlagEvaluationContext context, CancellationToken ct = default); /// public virtual Task> ListFlagsAsync( CancellationToken ct = default) { return Task.FromResult>([]); } /// public virtual async IAsyncEnumerable WatchAsync( [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct = default) { // Default implementation does nothing await Task.CompletedTask; yield break; } /// /// Creates a successful flag result. /// protected FeatureFlagResult CreateResult( string key, bool enabled, object? variant = null, string? reason = null) { return new FeatureFlagResult(key, enabled, variant, reason, Name); } }