Skip to content

A lightweight application built using C#, HTML, and CSS to showcase OpenFeature capabilities with a focus on feature flag integration.

License

Notifications You must be signed in to change notification settings

askpt/openfeature-aspire-welcome

Repository files navigation

OpenFeature Aspire Welcome

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.

Overview

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

Features

  • 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 application
    • return-weather-forecast: Controls the number of weather forecasts returned by the API
    • page-v2: Controls the display of a new page version with country-based targeting

Prerequisites

Setup

1. Clone the repository

git clone https://github.com/askpt/openfeature-aspire-welcome.git
cd openfeature-aspire-welcome

2. Configure flagd source location

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"

3. Build and run the application

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.

Project Structure

  • 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

Feature Flags

The application uses the following feature flags:

  1. use-new-counter-version:

    • When enabled, the counter will increase by a random value
    • When disabled, the counter will increase by 1
  2. return-weather-forecast:

    • Controls how many weather forecasts the API returns (3 or 5)
  3. 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

Modifying Feature Flags

You can modify the feature flags by editing the flagd/flagd.json file. After making changes, restart the application to see the effects.

Additional Resources

About

A lightweight application built using C#, HTML, and CSS to showcase OpenFeature capabilities with a focus on feature flag integration.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •