.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-flagcontainer is started for you, nodocker runand 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
/healthendpoint 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.
The Aspire integration is maintained by the Aspire Community Toolkit, not by the GO Feature Flag team. The full reference lives on aspire.dev.
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.
- C#
- TypeScript
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();
import { createBuilder } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const goff = await builder.addGoFeatureFlag('goff', {
pathToConfigFile: '/goff/goff-proxy.yaml',
});
await goff.withGoffBindMount('./goff');
const api = await builder.addProject(
'apiservice',
'../ExampleProject/ExampleProject.csproj'
);
await api.withReference(goff);
await builder.build().run();
WithGoffBindMountmounts a local folder into the/goffpath inside the container, this is where the relay proxy reads its configuration from.pathToConfigFileis passed to the relay proxy as its--configargument.WithReferenceinjects 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.
retrievers:
- kind: file
path: /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 variable | Description |
|---|---|
GOFF_URI | Base URL of the relay proxy (http://{host}:{port}) |
GOFF_HOST | Hostname or IP address of the relay proxy |
GOFF_PORT | Port the relay proxy is listening on |
ConnectionStrings__goff | Connection 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:
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.