Перейти к содержимому

flagd Client integration reference

Это содержимое пока не доступно на вашем языке.

⭐ Community Toolkit flagd logo

To get started with the Aspire flagd integrations, follow the Get started with flagd integrations guide.

This article includes full details about connecting to flagd from your consuming projects using the OpenFeature SDK.

To get started with the Aspire flagd client integration, install an OpenFeature provider for .NET. The most common provider for flagd is the OpenFeature.Contrib.Providers.Flagd NuGet package in the client-consuming project:

Terminal window
dotnet add package OpenFeature.Contrib.Providers.Flagd

In the Program.cs file of your client-consuming project, configure the OpenFeature SDK to use the flagd provider:

using OpenFeature;
using OpenFeature.Contrib.Providers.Flagd;
var connectionString = builder.Configuration.GetConnectionString("flagd");
await OpenFeature.Api.Instance.SetProviderAsync(
new FlagdProvider(new Uri(connectionString)));
var flagClient = OpenFeature.Api.Instance.GetClient();

You can then use the flagClient to evaluate feature flags:

var welcomeBanner = await flagClient.GetBooleanValueAsync(
"welcome-banner",
defaultValue: false);
var backgroundColor = await flagClient.GetStringValueAsync(
"background-color",
defaultValue: "#000000");

For more information on the OpenFeature SDK and flagd provider, see the OpenFeature .NET documentation and the flagd provider documentation.

The flagd client integration uses the connection string from the ConnectionStrings configuration section. The connection string is automatically provided when you reference the flagd resource in your app host project using WithReference.

The connection string format is:

http://localhost:<port>

Where <port> is the port assigned to the flagd HTTP endpoint.