コンテンツにスキップ
Docs Try Aspire
Docs Try

Connect to GO Feature Flag

このコンテンツはまだ日本語訳がありません。

⭐ Community Toolkit GO Feature Flag logo

This page describes how consuming apps connect to a GO Feature Flag relay proxy resource that’s already modeled in your AppHost. For the AppHost API surface — adding a relay proxy resource, bind mounts, data volumes, log levels, and more — see GO Feature Flag Hosting integration.

When you reference a GO Feature Flag resource from your AppHost, Aspire injects the relay proxy endpoint into the consuming app as environment variables. Your app can either read those environment variables directly — the pattern works the same from any language — or, in C#, use the Aspire GO Feature Flag client integration for automatic dependency injection and health checks.

Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Uri property of a resource called goff becomes GOFF_URI.

The GO Feature Flag resource exposes the following connection properties:

Property NameDescription
HostThe hostname or IP address of the GO Feature Flag relay proxy
PortThe port number the relay proxy is listening on
UriThe HTTP base URL of the relay proxy, with the format http://{Host}:{Port}

The connection string injected into ConnectionStrings__goff uses the format Endpoint=http://{Host}:{Port}.

Example connection values:

Uri: http://localhost:1031
ConnectionStrings__goff: Endpoint=http://localhost:1031

Pick the language your consuming app is written in. Each example assumes your AppHost adds a GO Feature Flag resource named goff and references it from the consuming app.

For C# apps, the recommended approach is the Aspire GO Feature Flag client integration. It registers a GOFeatureFlagProvider through dependency injection and adds health checks automatically. If you’d rather read environment variables directly, see the Read environment variables section at the end of this tab.

Install the 📦 CommunityToolkit.Aspire.GoFeatureFlag NuGet package in the client-consuming project:

.NET CLI — Add CommunityToolkit.Aspire.GoFeatureFlag package
dotnet add package CommunityToolkit.Aspire.GoFeatureFlag

In Program.cs, call AddGoFeatureFlagClient on your IHostApplicationBuilder to register a GOFeatureFlagProvider:

C# — Program.cs
builder.AddGoFeatureFlagClient(connectionName: "goff");

Resolve the provider through dependency injection:

C# — ExampleService.cs
using OpenFeature.Providers.GOFeatureFlag;
public class ExampleService(GOFeatureFlagProvider provider)
{
// Use provider to evaluate feature flags...
}

To register multiple GOFeatureFlagProvider instances with different connection names, use AddKeyedGoFeatureFlagClient:

C# — Program.cs
builder.AddKeyedGoFeatureFlagClient(name: "technical");
builder.AddKeyedGoFeatureFlagClient(name: "business");

Then resolve each instance by key:

C# — ExampleService.cs
using OpenFeature.Providers.GOFeatureFlag;
public class ExampleService(
[FromKeyedServices("technical")] GOFeatureFlagProvider technicalProvider,
[FromKeyedServices("business")] GOFeatureFlagProvider businessProvider)
{
// Use providers...
}

For more information, see .NET dependency injection: Keyed services.

The Aspire GO Feature Flag client integration offers multiple ways to provide configuration.

Connection strings. When using a connection string from the ConnectionStrings configuration section, pass the connection name to AddGoFeatureFlagClient:

C# — Program.cs
builder.AddGoFeatureFlagClient("goff");

The connection string is resolved from the ConnectionStrings section. It is accepted either as a bare URL or in the Endpoint=... key-value format:

JSON — appsettings.json
{
"ConnectionStrings": {
"goff": "Endpoint=http://myserver:1031"
}
}

Configuration providers. The client integration supports Microsoft.Extensions.Configuration. It loads GoFeatureFlagClientSettings from appsettings.json (or any other configuration source) by using the Aspire:GoFeatureFlag:Client key:

JSON — appsettings.json
{
"Aspire": {
"GoFeatureFlag": {
"Client": {
"Endpoint": "http://myserver:1031",
"DisableHealthChecks": false,
"HealthCheckTimeout": 5000
}
}
}
}

Inline delegates. Pass an Action<GoFeatureFlagClientSettings> to configure settings inline, for example to disable health checks:

C# — Program.cs
builder.AddGoFeatureFlagClient(
"goff",
static settings => settings.DisableHealthChecks = true);

Aspire client integrations enable health checks by default. The GO Feature Flag client integration adds a health check that calls the relay proxy /health endpoint to verify it is reachable. The health check is wired into the /health HTTP endpoint of your app, where all registered health checks must pass before the app is considered ready to accept traffic.

If you prefer not to use the Aspire client integration, you can read the Aspire-injected URI from the environment and configure the OpenFeature GOFeatureFlagProvider directly:

C# — Program.cs
using OpenFeature;
using OpenFeature.Providers.GOFeatureFlag;
var endpoint = Environment.GetEnvironmentVariable("GOFF_URI");
var provider = new GOFeatureFlagProvider(new GOFeatureFlagProviderOptions
{
Endpoint = endpoint + "/",
});
await OpenFeature.Api.Instance.SetProviderAsync(provider);
var client = OpenFeature.Api.Instance.GetClient();
// Use client to evaluate feature flags...