Listen to this Post
Trunk-based development is a branching strategy where all developers work directly on the “trunk” (main branch). Feature flags are essential in this approach to hide incomplete features until they are ready for release. ASP.NET Core provides built-in support for feature flags, making it easier to manage feature toggles.
You Should Know:
To get started with feature flags in ASP.NET Core, follow these steps:
1. Install the Microsoft.FeatureManagement NuGet package:
dotnet add package Microsoft.FeatureManagement
2. Configure feature flags in `appsettings.json`:
{
"FeatureManagement": {
"FeatureA": true,
"FeatureB": false
}
}
3. Register the feature management services in `Startup.cs`:
public void ConfigureServices(IServiceCollection services)
{
services.AddFeatureManagement();
}
- Use feature flags in your controllers or views:
[FeatureGate("FeatureA")] public IActionResult FeatureA() { return View(); }
5. Conditional rendering in Razor views:
@using Microsoft.FeatureManagement
@inject IFeatureManager FeatureManager
@if (await FeatureManager.IsEnabledAsync("FeatureA"))
{
Feature A is enabled!
}
Practice Verified Commands and Steps:
- Enable a feature flag dynamically:
await FeatureManager.EnableAsync("FeatureA"); -
Disable a feature flag dynamically:
await FeatureManager.DisableAsync("FeatureA"); -
Check feature flag status:
bool isEnabled = await FeatureManager.IsEnabledAsync("FeatureA"); -
Use feature flags in middleware:
app.Use(async (context, next) => { if (await FeatureManager.IsEnabledAsync("FeatureA")) { await context.Response.WriteAsync("Feature A is enabled!"); } await next(); });
What Undercode Say:
Trunk-based development, combined with feature flags, offers a streamlined approach to continuous integration and delivery. By leveraging ASP.NET Core’s built-in support for feature management, teams can effectively manage feature rollouts and ensure a stable main branch. However, this approach requires discipline and regular cleanup of feature flags to avoid technical debt.
For further reading, check out the official documentation on Feature Management in ASP.NET Core.
Related Linux/Windows Commands:
- Linux:
</li> </ul> <h1>Check Git branch</h1> git branch <h1>Merge a branch into trunk</h1> git merge feature-branch <h1>Rebase from main</h1> git rebase main
- Windows:
</li> </ul> <h1>Check Git branch</h1> git branch <h1>Merge a branch into trunk</h1> git merge feature-branch <h1>Rebase from main</h1> git rebase main
By following these steps and commands, you can effectively implement trunk-based development and feature flags in your .NET Core projects.
References:
Reported By: Milan Jovanovic – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅Join Our Cyber World:
- Windows:



