A sample application demonstrating the integration of OpenFeature with .NET Aspire for feature flag management. This application uses the flagd provider to deliver feature flags to the applications in the solution.
This project is a demonstration of how to integrate OpenFeature with .NET Aspire to create a powerful, cloud-native application with feature flag capabilities. The solution consists of:
- Todo.Web: A Blazor web application that consumes feature flags
- Todo.ApiService: An API service that also uses feature flags
- Todo.AppHost: The Aspire host that coordinates the application components
- Todo.ServiceDefaults: Common services and configurations used across the application
- flagd: A feature flag provider that serves feature flags to the application
- Integration of OpenFeature with .NET Aspire
- Feature flag management using flagd
- Sample feature flags demonstrating different use cases:
use-new-counter-version
: Controls the counter increment behaviour in the web applicationreturn-weather-forecast
: Controls the number of weather forecasts returned by the APIpage-v2
: Controls the display of a new page version with country-based targeting
- .NET 9 SDK or later
- Docker for running the services
git clone https://github.com/askpt/openfeature-aspire-welcome.git
cd openfeature-aspire-welcome
The application needs to know where the flagd configuration file is located. You need to set this using .NET user secrets:
cd Todo.AppHost
dotnet user-secrets init
dotnet user-secrets set "flagd:Source" "$(pwd)/../flagd"
Note for Unix-like systems: This sets the absolute path to your flagd folder in the user secrets. The AppHost will use this path to mount the flagd configuration file to the container.
Note for Windows users: If you are using PowerShell, replace
$(pwd)
with$(Get-Location)
in the command above. For example:dotnet user-secrets set "flagd:Source" "$(Get-Location)/../flagd"
dotnet build
cd Todo.AppHost
dotnet run
The Aspire dashboard will open automatically, showing the status of all services. From there, you can navigate to the web application.
- Todo.Web: Contains the frontend Blazor application
- Uses the counter feature flag to demonstrate different behaviours
- Todo.ApiService: Contains the backend API service
- Uses a feature flag to control the number of weather forecasts returned
- Todo.AppHost: The Aspire host application
- Configures and orchestrates all services
- Sets up the flagd container
- Todo.ServiceDefaults: Common configuration for all services
- Configures OpenFeature, OpenTelemetry, and other cross-cutting concerns
- flagd: Contains the feature flag configuration
The application uses the following feature flags:
-
use-new-counter-version:
- When enabled, the counter will increase by a random value
- When disabled, the counter will increase by 1
-
return-weather-forecast:
- Controls how many weather forecasts the API returns (3 or 5)
-
page-v2:
- Currently disabled by default
- When enabled for users in Portugal (
country
equals "pt"), shows a new page design - Otherwise, displays the original page design
- Uses targeting rules to gradually roll out the new design to specific users
You can modify the feature flags by editing the flagd/flagd.json
file. After making changes, restart the application to see the effects.