Get started with the flagd integrations
Цей контент ще не доступний вашою мовою.
flagd is a feature flag evaluation engine that provides an OpenFeature-compliant backend system for managing and evaluating feature flags in real-time. The Aspire flagd integration enables you to create new container instances from Aspire with the ghcr.io/open-feature/flagd container image.
flagd is designed to be a flexible, open-source feature flag evaluation engine. It enables real-time flag modifications, supports various flag types (boolean, string, number, JSON), uses context-sensitive rules for targeting, and performs pseudorandom assignments for experimentation. You can aggregate flag definitions from multiple sources and expose them through gRPC or OFREP services.
In this introduction, you’ll see how to install and use the Aspire flagd integrations in a simple configuration. If you already have this knowledge, see flagd hosting integration for full reference details.
Set up hosting integration
Section titled “Set up hosting integration”To begin, install the Aspire flagd hosting integration in your Aspire AppHost project:
aspire add communitytoolkit-flagdAspire CLI інтерактивний; оберіть відповідний результат пошуку:
Select an integration to add:
> communitytoolkit-flagd (CommunityToolkit.Aspire.Hosting.Flagd)> Other results listed as selectable options...#:package CommunityToolkit.Aspire.Hosting.Flagd@*<PackageReference Include="CommunityToolkit.Aspire.Hosting.Flagd" Version="*" />In your app host project, call AddFlagd on the builder instance to add a flagd container resource, and use WithBindFileSync to configure file-based flag synchronization:
var builder = DistributedApplication.CreateBuilder(args);
var flagd = builder.AddFlagd("flagd") .WithBindFileSync("./flags/");
builder.AddProject<Projects.ExampleProject>() .WithReference(flagd);
// After adding all resources, run the app...Flag definitions are stored in JSON files. Create a flags folder in your project root and add a flagd.json file with your flag configurations. For full details on the hosting integration, see flagd hosting integration.
Set up client integration
Section titled “Set up client integration”To connect to flagd from a consuming project, install the OpenFeature flagd provider package:
dotnet add package OpenFeature.Contrib.Providers.FlagdIn 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 full reference details, see flagd hosting integration and flagd client integration.