feature-flags
Microsoft.FeatureManagement patterns for feature toggles, gradual rollouts, and A/B testing in ASP.NET Core Razor Pages applications. Use when implementing feature toggles in ASP.NET Core applications, setting up gradual feature rollouts, or configuring A/B testing scenarios with feature flags.
What this skill does
## Rationale
Feature flags enable safe deployments, gradual rollouts, A/B testing, and quick rollback capabilities. Without proper feature flag patterns, teams risk deploying incomplete features or cannot respond quickly to production issues. These patterns provide a robust, maintainable approach to feature management in Razor Pages applications.
## Patterns
### Pattern 1: Configuration-Based Feature Flags
Use `appsettings.json` for simple feature toggles with environment-specific overrides.
```json
// appsettings.json
{
"FeatureManagement": {
"NewDashboard": false,
"BetaFeature": false,
"DarkMode": true,
"PaymentV2": {
"EnabledFor": [
{
"Name": "Microsoft.Targeting",
"Parameters": {
"Audience": {
"Users": [ "[email protected]" ],
"Groups": [ "BetaTesters" ],
"DefaultRolloutPercentage": 0
}
}
}
]
}
}
}
// appsettings.Production.json
{
"FeatureManagement": {
"NewDashboard": true,
"PaymentV2": {
"EnabledFor": [
{
"Name": "Microsoft.Targeting",
"Parameters": {
"Audience": {
"Users": [ "[email protected]" ],
"Groups": [ "BetaTesters" ],
"DefaultRolloutPercentage": 25
}
}
}
]
}
}
}
```
```csharp
// Program.cs - Basic setup
builder.Services.AddFeatureManagement();
// With custom configuration section
builder.Services.AddFeatureManagement(
builder.Configuration.GetSection("FeatureManagement"));
// With feature filters
builder.Services.AddFeatureManagement()
.AddFeatureFilter<TargetingFilter>()
.AddFeatureFilter<PercentageFilter>()
.AddFeatureFilter<TimeWindowFilter>();
```
### Pattern 2: Typed Feature Flags
Create strongly-typed feature flags for compile-time safety and discoverability.
```csharp
// Feature flag constants
public static class FeatureFlags
{
public const string NewDashboard = "NewDashboard";
public const string BetaFeature = "BetaFeature";
public const string DarkMode = "DarkMode";
public const string PaymentV2 = "PaymentV2";
public const string ApiRateLimiting = "ApiRateLimiting";
public const string AdvancedReporting = "AdvancedReporting";
}
// Feature-aware service interface
public interface IFeatureAwareService
{
Task<bool> IsEnabledAsync(string featureName);
Task<bool> IsEnabledAsync<TContext>(string featureName, TContext context);
}
public class FeatureService : IFeatureAwareService
{
private readonly IFeatureManager _featureManager;
public FeatureService(IFeatureManager featureManager)
{
_featureManager = featureManager;
}
public Task<bool> IsEnabledAsync(string featureName) =>
_featureManager.IsEnabledAsync(featureName);
public Task<bool> IsEnabledAsync<TContext>(string featureName, TContext context) =>
_featureManager.IsEnabledAsync(featureName, context);
}
// Extension methods for easier usage
public static class FeatureManagerExtensions
{
public static Task<bool> IsNewDashboardEnabledAsync(this IFeatureManager manager) =>
manager.IsEnabledAsync(FeatureFlags.NewDashboard);
public static Task<bool> IsPaymentV2EnabledAsync(this IFeatureManager manager, string userId) =>
manager.IsEnabledAsync(FeatureFlags.PaymentV2, new TargetingContext { UserId = userId });
}
```
### Pattern 3: Razor Pages Integration
Use feature flags in Razor Pages for conditional UI rendering and routing.
```csharp
// PageModel with feature flag checks
public class DashboardModel : PageModel
{
private readonly IFeatureManager _featureManager;
public DashboardModel(IFeatureManager featureManager)
{
_featureManager = featureManager;
}
public bool UseNewDashboard { get; private set; }
public bool IsDarkModeEnabled { get; private set; }
public async Task OnGetAsync()
{
UseNewDashboard = await _featureManager.IsEnabledAsync(FeatureFlags.NewDashboard);
IsDarkModeEnabled = await _featureManager.IsEnabledAsync(FeatureFlags.DarkMode);
}
}
// View with conditional rendering
@page
@model DashboardModel
@inject IFeatureManager FeatureManager
@if (Model.UseNewDashboard)
{
<partial name="_NewDashboard" model="Model" />
}
else
{
<partial name="_LegacyDashboard" model="Model" />
}
@if (await FeatureManager.IsEnabledAsync(FeatureFlags.BetaFeature))
{
<div class="alert alert-info">
<strong>Beta:</strong> Try our new experimental features!
</div>
}
@if (Model.IsDarkModeEnabled)
{
<button id="theme-toggle" class="btn btn-outline-secondary">
Toggle Dark Mode
</button>
}
```
### Pattern 4: Feature Gate Action Filter
Use the built-in feature gate filter for controller/page-level feature control.
```csharp
// Controller/PageModel level feature gate
[FeatureGate(FeatureFlags.BetaFeature)]
public class BetaFeaturesModel : PageModel
{
public void OnGet()
{
// This page is only accessible when BetaFeature is enabled
}
}
// Alternative: Redirect to different page
[FeatureGate(FeatureFlags.NewDashboard,
RequirementType.All, // All features must be enabled
NoFeatureRedirect = "/Dashboard/Legacy")]
public class NewDashboardModel : PageModel
{
// Redirects to legacy dashboard if NewDashboard is disabled
}
// Custom feature gate attribute for complex scenarios
public class PremiumFeatureAttribute : FeatureGateAttribute
{
public PremiumFeatureAttribute()
: base(FeatureFlags.AdvancedReporting)
{
}
}
[PremiumFeature]
public class ReportsModel : PageModel
{
// Premium feature page
}
```
### Pattern 5: Gradual Rollout with Targeting
Implement user-based and percentage-based rollouts safely.
```csharp
// Custom targeting context
public class FeatureTargetingContext : ITargetingContext
{
public string? UserId { get; set; }
public List<string> Groups { get; set; } = new();
}
// Targeting context accessor
public class HttpContextTargetingContextAccessor : ITargetingContextAccessor
{
private readonly IHttpContextAccessor _httpContextAccessor;
public HttpContextTargetingContextAccessor(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public ValueTask<TargetingContext> GetContextAsync()
{
var httpContext = _httpContextAccessor.HttpContext;
if (httpContext?.User?.Identity?.IsAuthenticated != true)
{
return ValueTask.FromResult(new TargetingContext());
}
var context = new TargetingContext
{
UserId = httpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value,
Groups = httpContext.User.FindAll(ClaimTypes.Role)
.Select(c => c.Value)
.ToList()
};
return ValueTask.FromResult(context);
}
}
// Registration
builder.Services.AddHttpContextAccessor();
builder.Services.AddSingleton<ITargetingContextAccessor, HttpContextTargetingContextAccessor>();
builder.Services.AddFeatureManagement()
.AddFeatureFilter<TargetingFilter>();
// Usage in PageModel
public class CheckoutModel : PageModel
{
private readonly IFeatureManager _featureManager;
public CheckoutModel(IFeatureManager featureManager)
{
_featureManager = featureManager;
}
public async Task<IActionResult> OnPostAsync()
{
var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? "anonymous";
if (await _featureManager.IsEnabledAsync(FeatureFlags.PaymentV2, new
{
UserId = userId,
Groups = User.FindAll(ClaimTypes.Role).Select(c => c.Value).ToList()
}))
{
return await ProcessPaymentV2Async();
}
return await ProcessLegacyPaymentAsync();
}
}
```
### Pattern 6: Time-Based Feature Flags
Enable featuresRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.