From 937a9623e7e52f2c682f5015b464eacafc9caf75 Mon Sep 17 00:00:00 2001 From: Chris Donnelly Date: Fri, 13 Jan 2023 15:55:59 -0600 Subject: [PATCH 1/4] feat: Make IFeatureClient interface public. Additional necessary changes: - Pulls up the documentation from the concrete class to the interface. Signed-off-by: Chris Donnelly --- src/OpenFeature/IFeatureClient.cs | 102 +++++++++++++++++++++++++- src/OpenFeature/OpenFeatureClient.cs | 103 ++++----------------------- 2 files changed, 113 insertions(+), 92 deletions(-) diff --git a/src/OpenFeature/IFeatureClient.cs b/src/OpenFeature/IFeatureClient.cs index f1fd4ad8..8844b8c0 100644 --- a/src/OpenFeature/IFeatureClient.cs +++ b/src/OpenFeature/IFeatureClient.cs @@ -4,24 +4,124 @@ namespace OpenFeature { - internal interface IFeatureClient + /// + /// Interface used to resolve flags of varying types. + /// + public interface IFeatureClient { + /// + /// Appends hooks to client + /// + /// The appending operation will be atomic. + /// + /// + /// A list of Hooks that implement the interface void AddHooks(IEnumerable hooks); + + /// + /// Gets client metadata + /// + /// Client metadata ClientMetadata GetMetadata(); + /// + /// Resolves a boolean feature flag + /// + /// Feature flag key + /// Default value + /// Evaluation Context + /// Flag Evaluation Options + /// Resolved flag details Task GetBooleanValue(string flagKey, bool defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); + + /// + /// Resolves a boolean feature flag + /// + /// Feature flag key + /// Default value + /// Evaluation Context + /// Flag Evaluation Options + /// Resolved flag details Task> GetBooleanDetails(string flagKey, bool defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); + /// + /// Resolves a string feature flag + /// + /// Feature flag key + /// Default value + /// Evaluation Context + /// Flag Evaluation Options + /// Resolved flag details Task GetStringValue(string flagKey, string defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); + + /// + /// Resolves a string feature flag + /// + /// Feature flag key + /// Default value + /// Evaluation Context + /// Flag Evaluation Options + /// Resolved flag details Task> GetStringDetails(string flagKey, string defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); + /// + /// Resolves a integer feature flag + /// + /// Feature flag key + /// Default value + /// Evaluation Context + /// Flag Evaluation Options + /// Resolved flag details Task GetIntegerValue(string flagKey, int defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); + + /// + /// Resolves a integer feature flag + /// + /// Feature flag key + /// Default value + /// Evaluation Context + /// Flag Evaluation Options + /// Resolved flag details Task> GetIntegerDetails(string flagKey, int defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); + /// + /// Resolves a double feature flag + /// + /// Feature flag key + /// Default value + /// Evaluation Context + /// Flag Evaluation Options + /// Resolved flag details Task GetDoubleValue(string flagKey, double defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); + + /// + /// Resolves a double feature flag + /// + /// Feature flag key + /// Default value + /// Evaluation Context + /// Flag Evaluation Options + /// Resolved flag details Task> GetDoubleDetails(string flagKey, double defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); + /// + /// Resolves a structure object feature flag + /// + /// Feature flag key + /// Default value + /// Evaluation Context + /// Flag Evaluation Options + /// Resolved flag details Task GetObjectValue(string flagKey, Value defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); + + /// + /// Resolves a structure object feature flag + /// + /// Feature flag key + /// Default value + /// Evaluation Context + /// Flag Evaluation Options + /// Resolved flag details Task> GetObjectDetails(string flagKey, Value defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); } } diff --git a/src/OpenFeature/OpenFeatureClient.cs b/src/OpenFeature/OpenFeatureClient.cs index f33fb1a7..7fe8e21f 100644 --- a/src/OpenFeature/OpenFeatureClient.cs +++ b/src/OpenFeature/OpenFeatureClient.cs @@ -97,10 +97,7 @@ public FeatureClient(string name, string version, ILogger logger = null, Evaluat this._evaluationContext = context ?? EvaluationContext.Empty; } - /// - /// Gets client metadata - /// - /// Client metadata + /// public ClientMetadata GetMetadata() => this._metadata; /// @@ -113,13 +110,7 @@ public FeatureClient(string name, string version, ILogger logger = null, Evaluat /// Hook that implements the interface public void AddHooks(Hook hook) => this._hooks.Push(hook); - /// - /// Appends hooks to client - /// - /// The appending operation will be atomic. - /// - /// - /// A list of Hooks that implement the interface + /// public void AddHooks(IEnumerable hooks) => this._hooks.PushRange(hooks.ToArray()); /// @@ -138,131 +129,61 @@ public FeatureClient(string name, string version, ILogger logger = null, Evaluat /// public void ClearHooks() => this._hooks.Clear(); - /// - /// Resolves a boolean feature flag - /// - /// Feature flag key - /// Default value - /// Evaluation Context - /// Flag Evaluation Options - /// Resolved flag details + /// public async Task GetBooleanValue(string flagKey, bool defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null) => (await this.GetBooleanDetails(flagKey, defaultValue, context, config)).Value; - /// - /// Resolves a boolean feature flag - /// - /// Feature flag key - /// Default value - /// Evaluation Context - /// Flag Evaluation Options - /// Resolved flag details + /// public async Task> GetBooleanDetails(string flagKey, bool defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null) => await this.EvaluateFlag(this.ExtractProvider(provider => provider.ResolveBooleanValue), FlagValueType.Boolean, flagKey, defaultValue, context, config); - /// - /// Resolves a string feature flag - /// - /// Feature flag key - /// Default value - /// Evaluation Context - /// Flag Evaluation Options - /// Resolved flag details + /// public async Task GetStringValue(string flagKey, string defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null) => (await this.GetStringDetails(flagKey, defaultValue, context, config)).Value; - /// - /// Resolves a string feature flag - /// - /// Feature flag key - /// Default value - /// Evaluation Context - /// Flag Evaluation Options - /// Resolved flag details + /// public async Task> GetStringDetails(string flagKey, string defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null) => await this.EvaluateFlag(this.ExtractProvider(provider => provider.ResolveStringValue), FlagValueType.String, flagKey, defaultValue, context, config); - /// - /// Resolves a integer feature flag - /// - /// Feature flag key - /// Default value - /// Evaluation Context - /// Flag Evaluation Options - /// Resolved flag details + /// public async Task GetIntegerValue(string flagKey, int defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null) => (await this.GetIntegerDetails(flagKey, defaultValue, context, config)).Value; - /// - /// Resolves a integer feature flag - /// - /// Feature flag key - /// Default value - /// Evaluation Context - /// Flag Evaluation Options - /// Resolved flag details + /// public async Task> GetIntegerDetails(string flagKey, int defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null) => await this.EvaluateFlag(this.ExtractProvider(provider => provider.ResolveIntegerValue), FlagValueType.Number, flagKey, defaultValue, context, config); - /// - /// Resolves a double feature flag - /// - /// Feature flag key - /// Default value - /// Evaluation Context - /// Flag Evaluation Options - /// Resolved flag details + /// public async Task GetDoubleValue(string flagKey, double defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null) => (await this.GetDoubleDetails(flagKey, defaultValue, context, config)).Value; - /// - /// Resolves a double feature flag - /// - /// Feature flag key - /// Default value - /// Evaluation Context - /// Flag Evaluation Options - /// Resolved flag details + /// public async Task> GetDoubleDetails(string flagKey, double defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null) => await this.EvaluateFlag(this.ExtractProvider(provider => provider.ResolveDoubleValue), FlagValueType.Number, flagKey, defaultValue, context, config); - /// - /// Resolves a structure object feature flag - /// - /// Feature flag key - /// Default value - /// Evaluation Context - /// Flag Evaluation Options - /// Resolved flag details + /// public async Task GetObjectValue(string flagKey, Value defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null) => (await this.GetObjectDetails(flagKey, defaultValue, context, config)).Value; - /// - /// Resolves a structure object feature flag - /// - /// Feature flag key - /// Default value - /// Evaluation Context - /// Flag Evaluation Options - /// Resolved flag details + /// public async Task> GetObjectDetails(string flagKey, Value defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null) => await this.EvaluateFlag(this.ExtractProvider(provider => provider.ResolveStructureValue), From 9710d1c9b34783927267f5ac3b9a82c468f624e2 Mon Sep 17 00:00:00 2001 From: Chris Donnelly Date: Tue, 17 Jan 2023 11:29:39 -0600 Subject: [PATCH 2/4] fix: Docs for value methods now state they return the value. Signed-off-by: Chris Donnelly --- src/OpenFeature/IFeatureClient.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OpenFeature/IFeatureClient.cs b/src/OpenFeature/IFeatureClient.cs index 8844b8c0..13ac7c52 100644 --- a/src/OpenFeature/IFeatureClient.cs +++ b/src/OpenFeature/IFeatureClient.cs @@ -31,7 +31,7 @@ public interface IFeatureClient /// Default value /// Evaluation Context /// Flag Evaluation Options - /// Resolved flag details + /// Resolved flag value. Task GetBooleanValue(string flagKey, bool defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); /// @@ -51,7 +51,7 @@ public interface IFeatureClient /// Default value /// Evaluation Context /// Flag Evaluation Options - /// Resolved flag details + /// Resolved flag value. Task GetStringValue(string flagKey, string defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); /// @@ -71,7 +71,7 @@ public interface IFeatureClient /// Default value /// Evaluation Context /// Flag Evaluation Options - /// Resolved flag details + /// Resolved flag value. Task GetIntegerValue(string flagKey, int defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); /// @@ -91,7 +91,7 @@ public interface IFeatureClient /// Default value /// Evaluation Context /// Flag Evaluation Options - /// Resolved flag details + /// Resolved flag value. Task GetDoubleValue(string flagKey, double defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); /// @@ -111,7 +111,7 @@ public interface IFeatureClient /// Default value /// Evaluation Context /// Flag Evaluation Options - /// Resolved flag details + /// Resolved flag value. Task GetObjectValue(string flagKey, Value defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null); /// From a9804121b385f80271d3c23a038f403614ee77c2 Mon Sep 17 00:00:00 2001 From: Chris Donnelly Date: Tue, 17 Jan 2023 11:51:02 -0600 Subject: [PATCH 3/4] feat: Pull up methods to interface. - GetContext() / SetContext(EvaluationContext) - GetHooks() Signed-off-by: Chris Donnelly --- src/OpenFeature/IFeatureClient.cs | 28 ++++++++++++++++++++++++++++ src/OpenFeature/OpenFeatureClient.cs | 25 +++---------------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/OpenFeature/IFeatureClient.cs b/src/OpenFeature/IFeatureClient.cs index 13ac7c52..fc0d5aec 100644 --- a/src/OpenFeature/IFeatureClient.cs +++ b/src/OpenFeature/IFeatureClient.cs @@ -18,6 +18,34 @@ public interface IFeatureClient /// A list of Hooks that implement the interface void AddHooks(IEnumerable hooks); + /// + /// Enumerates the global hooks. + /// + /// The items enumerated will reflect the registered hooks + /// at the start of enumeration. Hooks added during enumeration + /// will not be included. + /// + /// + /// Enumeration of + IEnumerable GetHooks(); + + /// + /// Gets the EvaluationContext of this client + /// + /// The evaluation context may be set from multiple threads, when accessing the client evaluation context + /// it should be accessed once for an operation, and then that reference should be used for all dependent + /// operations. + /// + /// + /// of this client + EvaluationContext GetContext(); + + /// + /// Sets the EvaluationContext of the client + /// + /// The to set + void SetContext(EvaluationContext context); + /// /// Gets client metadata /// diff --git a/src/OpenFeature/OpenFeatureClient.cs b/src/OpenFeature/OpenFeatureClient.cs index 7fe8e21f..115f7510 100644 --- a/src/OpenFeature/OpenFeatureClient.cs +++ b/src/OpenFeature/OpenFeatureClient.cs @@ -53,15 +53,7 @@ public sealed class FeatureClient : IFeatureClient return (method(provider), provider); } - /// - /// Gets the EvaluationContext of this client - /// - /// The evaluation context may be set from multiple threads, when accessing the client evaluation context - /// it should be accessed once for an operation, and then that reference should be used for all dependent - /// operations. - /// - /// - /// of this client + /// public EvaluationContext GetContext() { lock (this._evaluationContextLock) @@ -70,10 +62,7 @@ public EvaluationContext GetContext() } } - /// - /// Sets the EvaluationContext of the client - /// - /// The to set + /// public void SetContext(EvaluationContext context) { lock (this._evaluationContextLock) @@ -113,15 +102,7 @@ public FeatureClient(string name, string version, ILogger logger = null, Evaluat /// public void AddHooks(IEnumerable hooks) => this._hooks.PushRange(hooks.ToArray()); - /// - /// Enumerates the global hooks. - /// - /// The items enumerated will reflect the registered hooks - /// at the start of enumeration. Hooks added during enumeration - /// will not be included. - /// - /// - /// Enumeration of + /// public IEnumerable GetHooks() => this._hooks.Reverse(); /// From 7aa75d77daabd596541dffc43cf982452834cce7 Mon Sep 17 00:00:00 2001 From: Chris Donnelly Date: Tue, 17 Jan 2023 11:54:57 -0600 Subject: [PATCH 4/4] fix: Fixing Get/SetContext docs. The extra "see" at the end made it read as "Gets the EvaluationContext of this clientEvaluationContext". Signed-off-by: Chris Donnelly --- src/OpenFeature/IFeatureClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenFeature/IFeatureClient.cs b/src/OpenFeature/IFeatureClient.cs index fc0d5aec..2186ca68 100644 --- a/src/OpenFeature/IFeatureClient.cs +++ b/src/OpenFeature/IFeatureClient.cs @@ -30,7 +30,7 @@ public interface IFeatureClient IEnumerable GetHooks(); /// - /// Gets the EvaluationContext of this client + /// Gets the of this client /// /// The evaluation context may be set from multiple threads, when accessing the client evaluation context /// it should be accessed once for an operation, and then that reference should be used for all dependent @@ -41,7 +41,7 @@ public interface IFeatureClient EvaluationContext GetContext(); /// - /// Sets the EvaluationContext of the client + /// Sets the of the client /// /// The to set void SetContext(EvaluationContext context);