Skip to main content
Version: v1.55.3

.NET Aspire

Overview

.NET Aspire is a code-first way to describe the services, containers and dependencies of your application in a single place.

The Aspire GO Feature Flag integration lets you model the relay proxy as a resource in your AppHost, which means:

  • The gofeatureflag/go-feature-flag container is started for you, no docker run and no hardcoded URL.
  • The relay proxy endpoint is injected into every app that references it as environment variables, so it works from C#, TypeScript, Python, Go or any other language.
  • A health check on the /health endpoint is registered automatically, so the Aspire dashboard knows when the relay proxy is ready.
  • Logs, traces and metrics of the relay proxy are surfaced in the Aspire dashboard through the OpenTelemetry exporter.
info

The Aspire integration is maintained by the Aspire Community Toolkit, not by the GO Feature Flag team. The full reference lives on aspire.dev.

note

This integration targets your local development inner loop. To run the relay proxy in production, have a look at Helm, AWS Lambda or start the container directly.

Prerequisites

  • The Aspire CLI installed on your machine.
  • A container runtime such as Docker or Podman.

Step 1: Add the hosting integration

Add the hosting integration to your AppHost project:

aspire add CommunityToolkit.Aspire.Hosting.GoFeatureFlag

Step 2: Declare the relay proxy resource

Declare a GO Feature Flag resource and reference it from the apps that need to evaluate flags.

AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);

var goff = builder.AddGoFeatureFlag("goff", pathToConfigFile: "/goff/goff-proxy.yaml")
.WithGoffBindMount("./goff");

var apiService = builder.AddProject<Projects.ExampleProject>("apiservice")
.WithReference(goff);

builder.Build().Run();
  • WithGoffBindMount mounts a local folder into the /goff path inside the container, this is where the relay proxy reads its configuration from.
  • pathToConfigFile is passed to the relay proxy as its --config argument.
  • WithReference injects the relay proxy connection information into the consuming app.

Data volumes, log levels and fixed host ports are described in the hosting integration reference.

Step 3: Provide the configuration

The bind-mounted folder must contain the relay proxy configuration and your flag definitions.

goff/goff-proxy.yaml
retrievers:
- kind: file
path: /goff/flags.yaml
goff/flags.yaml
display-banner:
variations:
enabled: true
disabled: false
defaultRule:
variation: enabled

All the available relay proxy options are listed in Configure the relay proxy, and the flag format is described in Create your flags.

Step 4: Connect your application

Aspire exposes the connection information of a resource as [RESOURCE]_[PROPERTY] environment variables. For a resource named goff you get:

Environment variableDescription
GOFF_URIBase URL of the relay proxy (http://{host}:{port})
GOFF_HOSTHostname or IP address of the relay proxy
GOFF_PORTPort the relay proxy is listening on
ConnectionStrings__goffConnection string, formatted as Endpoint=http://{host}:{port}

In a .NET application, the CommunityToolkit.Aspire.GoFeatureFlag client integration reads it for you and registers the provider in the dependency injection container:

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

In any other language, read GOFF_URI and use it as the endpoint of the OpenFeature provider of your choice. Note that the providers expect a trailing /, so append it to the value of GOFF_URI.

Going further