.NET
Installation
Add the OpenFeature
SDK and the Tggl.OpenFeature
provider to your project:
Quick start
Set the provider with your API key and create a client:
Getting a flag's value
There are four methods to get a flag's value: GetStringValueAsync
, GetBooleanValueAsync
, GetIntegerValueAsync
, and GetDoubleValueAsync
. Those four methods are guaranteed to return the expected type. If the flag's value is not of the expected type, the method will return the default value you provide.
Additionally, you can use the GetObjectValueAsync
method to get the flag's value regardless of its type (including arrays and objects):
The returned Value
class has type check methods (IsString
, IsBoolean
...) and conversion methods (AsList
, AsObject
...) to help you work with the value.
Evaluation context
When evaluating a flag you can create a context using the builder and pass it to the evaluation method:
You can also specify the context directly on the client or globally for all evaluations:
The contexts will then be merged with the context you pass to the evaluation method.
Reporting
By default, the SDK sends flag evaluation data to Tggl to give you precious insights on how you are actually using your flags in production and to help you manage flags lifecycles better.
The SDK sends at most one HTTP request every 5 seconds to Tggl. Additionally, you can identify the client making the request by giving it an app name. You will be able to retrieve that name on the Tggl dashboard:
You can also disable reporting entirely:
Using the Proxy
By default, the SDK talks directly to the Tggl API. If you are using the Tggl Proxy, you can specify the proxy URL when instantiating the client:
The /flags
and /report
path will be appended to the BaseUrl
and both flags evaluation and reporting will go through the proxy. If your proxy is configured with custom paths, you can specify them:
Evaluate flags locally
It is possible to evaluate flags locally on the server but not recommended unless you have performance issues evaluating flags at a high frequency. Evaluating flags locally forces you to maintain the copy of flags configuration up to date and might be a source of issues.
Make sure to add the right keys to your context to be perfectly consistent with the Tggl API.
The config will be fetched every 5 seconds by default. You can change this interval by passing a PollingInterval
parameter to the constructor.
Going further
Read the official OpenFeature SDK documentation for more information on how to use the SDK.
You can also have a look at Tggl's .NET SDK documentation that is used under the hood by the TgglProvider
.