Skip to content

Commit

Permalink
docs: use SetTargetingKey in Flagsmith example
Browse files Browse the repository at this point in the history
  • Loading branch information
ghelyar committed Jul 8, 2024
1 parent da439e2 commit 1ae840b
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions src/OpenFeature.Contrib.Providers.Flagsmith/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,42 @@ packet add OpenFeature.Contrib.Providers.Flagsmith
To create a Flagmith provider you should define provider and Flagsmith settings.

```csharp
using OpenFeature.Contrib.Providers.Flagd;
using Flagsmith;
using OpenFeature.Contrib.Providers.Flagsmith;
using OpenFeature.Model;

namespace OpenFeatureTestApp
// Additional configs for provider
var providerConfig = new FlagsmithProviderConfiguration();

// Flagsmith client configuration
var flagsmithConfig = new FlagsmithConfiguration
{
class Hello {
static void Main(string[] args) {

// Additional configs for provider
var providerConfig = new FlagsmithProviderConfiguration();

//Flagsmith client configuration
var flagsmithConfig = new FlagsmithConfiguration
{
ApiUrl = "https://edge.api.flagsmith.com/api/v1/",
EnvironmentKey = string.Empty,
EnableClientSideEvaluation = false,
EnvironmentRefreshIntervalSeconds = 60,
EnableAnalytics = false,
Retries = 1
};
var flagsmithProvider = new FlagsmithProvider(providerConfig, flagsmithConfig);\

// Set the flagsmithProvider as the provider for the OpenFeature SDK
OpenFeature.Api.Instance.SetProvider(flagsmithProvider);

var client = OpenFeature.Api.Instance.GetClient("my-app");

var val = client.GetBooleanValue("myBoolFlag", false, null);

// Print the value of the 'myBoolFlag' feature flag
System.Console.WriteLine(val.Result.ToString());
}
}
}
ApiUrl = "https://edge.api.flagsmith.com/api/v1/",
EnvironmentKey = "",
EnableClientSideEvaluation = false,
EnvironmentRefreshIntervalSeconds = 60,
EnableAnalytics = false,
Retries = 1,
};
var flagsmithProvider = new FlagsmithProvider(providerConfig, flagsmithConfig);

// Set the flagsmithProvider as the provider for the OpenFeature SDK
await OpenFeature.Api.Instance.SetProviderAsync(flagsmithProvider);

// Get an OpenFeature client
var client = OpenFeature.Api.Instance.GetClient("my-app");

// Optional: set a targeting key and traits to use segment and/or identity overrides
var context = EvaluationContext.Builder()
.SetTargetingKey("my-flagsmith-identity-ID")
.Set("my-trait-key", "my-trait-value")
.Build();

// Evaluate a flag
var val = await client.GetBooleanValue("myBoolFlag", false, context);

// Print the value of the 'myBoolFlag' feature flag
Console.WriteLine(val);
```

You also can create Flagsmith provider using ```HttpClient``` or precreated ```FlagsmithClient```
Expand Down

0 comments on commit 1ae840b

Please sign in to comment.