Skip to main content

Feature Flags Integration Guide

Choose your provider below and follow the 5-step integration guide.


Provider: InMemory (Standard)

Best for development and simple applications where flags are managed in standard configuration.

Step 1: Install the package

dotnet add package PrimusSaaS.FeatureFlags

Step 2: Configure Program.cs

using PrimusSaaS.FeatureFlags;

var builder = WebApplication.CreateBuilder(args);

// Register Feature Flags service
builder.Services.AddPrimusFeatureFlags(options =>
builder.Configuration.GetSection("PrimusFeatureFlags").Bind(options));

var app = builder.Build();

Step 3: Configure appsettings.json

Define your flags directly in the Flags object.

{
"PrimusFeatureFlags": {
"Provider": "InMemory",
"Flags": {
"NewDashboard": {
"Enabled": true,
"RolloutPercentage": 50
},
"BetaFeature": {
"Enabled": true,
"EnabledForUsers": ["user-123", "user-456"]
}
}
}
}

Step 4: Configure endpoint

Inject IFeatureFlagService into your controller.

using Microsoft.AspNetCore.Mvc;
using PrimusSaaS.FeatureFlags;

[ApiController]
[Route("api/[controller]")]
public class FeatureController : ControllerBase
{
private readonly IFeatureFlagService _flags;

public FeatureController(IFeatureFlagService flags)
{
_flags = flags;
}

[HttpGet("check/{feature}")]
public IActionResult CheckFeature(string feature)
{
var isEnabled = _flags.IsEnabled(feature);
return Ok(new { feature, enabled = isEnabled });
}
}

Step 5: Test the endpoint

curl http://localhost:5000/api/feature/check/NewDashboard

Provider: JsonFile

Best for scenarios requiring hot-reloading of flags without restarting the application.

Step 1: Install the package

dotnet add package PrimusSaaS.FeatureFlags

Step 2: Configure Program.cs

using PrimusSaaS.FeatureFlags;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddPrimusFeatureFlags(options =>
builder.Configuration.GetSection("PrimusFeatureFlags").Bind(options));

Step 3: Configure appsettings.json

Point the provider to an external JSON file.

{
"PrimusFeatureFlags": {
"Provider": "JsonFile",
"JsonFilePath": "flags.json"
}
}

Note: You must also create a flags.json file in your project root and ensure it is copied to the output directory.

flags.json:

{
"NewDashboard": {
"Enabled": true,
"Description": "New UI Version"
}
}

Step 4: Configure endpoint

Implementation is identical to the InMemory provider.

// Inject IFeatureFlagService as shown above

Step 5: Test the endpoint

curl http://localhost:5000/api/feature/check/NewDashboard

Provider: Azure App Configuration

Best for distributed systems requiring centralized management. This provider is not available in the core package yet.

Step 1: Install the package

dotnet add package PrimusSaaS.FeatureFlags

The Azure App Configuration provider requires a separate provider package. If it is not published in your feed yet, you cannot use this provider.

Step 2: Configure Program.cs

using PrimusSaaS.FeatureFlags;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddPrimusFeatureFlags(options =>
builder.Configuration.GetSection("PrimusFeatureFlags").Bind(options));

Step 3: Configure appsettings.json

Set the provider to AzureAppConfiguration and provide the connection string.

{
"PrimusFeatureFlags": {
"Provider": "AzureAppConfiguration",
"AzureAppConfigConnectionString": "Endpoint=https://your-config.azconfig.io;Id=...;Secret=...",
"CacheDurationSeconds": 60
}
}

Step 4: Configure endpoint

Implementation is identical to other providers.

// Inject IFeatureFlagService as shown above

Step 5: Test the endpoint

curl http://localhost:5000/api/feature/check/NewDashboard