Feature Flags Module - Overview
Lightweight, in-process feature toggles with optional user/group targeting and percentage rollouts. All evaluation runs inside your app - no remote calls. Supports local config, JSON files, environment variables (Node.js), and Azure App Configuration (.NET only).
Packages
- .NET:
PrimusSaaS.FeatureFlags(current: 2.0.0) - Node.js:
@primus-saas/feature-flags(current: 1.0.0)
Publish Status
PrimusSaaS.FeatureFlags is not yet on public NuGet. Use your internal feed or local build.
Key Capabilities
- Boolean feature toggles with global on/off
- Percentage-based rollouts (sticky by user ID)
- User and group targeting allow lists
- Time-based activation (start/end times)
- Multiple providers with local, JSON, and env support (Azure App Configuration on .NET)
- Real-time refresh with caching
Example API
GET /api/dashboard
Headers: Authorization: Bearer <JWT>
Response 200:
{
"dashboard": "new",
"flags": {
"NewDashboard": true,
"BetaFeature": false
}
}
Quick Install
# .NET
dotnet add package PrimusSaaS.FeatureFlags
# Node.js
npm install @primus-saas/feature-flags
.NET Example
using PrimusSaaS.FeatureFlags;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddPrimusFeatureFlags(opts =>
builder.Configuration.GetSection("PrimusFeatureFlags").Bind(opts));
var app = builder.Build();
app.MapControllers();
app.Run();
appsettings.json:
{
"PrimusFeatureFlags": {
"Flags": {
"NewDashboard": { "Enabled": true, "RolloutPercentage": 50 },
"BetaFeature": { "Enabled": true, "EnabledForUsers": ["user-123"] }
}
}
}
Node.js Example
import { FeatureFlagService } from '@primus-saas/feature-flags';
const featureFlags = new FeatureFlagService({
flags: {
newDashboard: {
enabled: true,
description: 'Enable the new dashboard UI',
},
betaFeature: {
enabled: false,
rolloutPercentage: 25,
enabledForGroups: ['beta-testers'],
},
},
});
if (featureFlags.isEnabled('newDashboard')) {
console.log('New dashboard is enabled!');
}
Controller Example
public class DashboardController : ControllerBase
{
private readonly IFeatureFlagService _flags;
public DashboardController(IFeatureFlagService flags) => _flags = flags;
[HttpGet]
public IActionResult Get()
{
var enabled = _flags.IsEnabled("NewDashboard");
return Ok(new { dashboard = enabled ? "new" : "legacy" });
}
}
Rollout
Use percentage rollouts to gradually enable a feature while keeping evaluations sticky per user.
{
"PrimusFeatureFlags": {
"Flags": {
"NewDashboard": { "Enabled": true, "RolloutPercentage": 25 }
}
}
}
User Targeting
Target specific users or groups with allow lists.
{
"PrimusFeatureFlags": {
"Flags": {
"BetaFeature": {
"Enabled": true,
"EnabledForUsers": ["user-123"],
"EnabledForGroups": ["beta-testers"]
}
}
}
}
Providers
.NET Providers
| Provider | Configuration |
|---|---|
| InMemory (default) | Flags from appsettings.json |
| JsonFile | Provider: "JsonFile", JsonFilePath: "flags.json" |
| Azure App Configuration | Provider: "AzureAppConfiguration" |
Node.js Providers
| Provider | Configuration |
|---|---|
| memory (default) | Flags from constructor config |
| json | provider: "json", jsonFilePath: "./flags.json" |
| env | provider: "env", envPrefix: "FEATURE_" |
See Also
- Feature Flags Quick Start
- Feature Flags Advanced
- Identity Validator (user context for targeting)