File tree Expand file tree Collapse file tree 5 files changed +46
-3
lines changed
21-azure-app-configuration Expand file tree Collapse file tree 5 files changed +46
-3
lines changed Original file line number Diff line number Diff line change 11using System . Diagnostics ;
22using Microsoft . AspNetCore . Mvc ;
3+ using Microsoft . FeatureManagement ;
34using SampleAppConfigAsp . Models ;
45
56namespace SampleAppConfigAsp . Controllers ;
67
78public class HomeController : Controller
89{
910 private readonly ILogger < HomeController > _logger ;
11+ private readonly IFeatureManager _featureManager ;
1012
11- public HomeController ( ILogger < HomeController > logger )
13+ public HomeController ( ILogger < HomeController > logger , IFeatureManager featureManager )
1214 {
1315 _logger = logger ;
16+ _featureManager = featureManager ;
1417 }
1518
16- public IActionResult Index ( )
19+ public async Task < IActionResult > Index ( )
1720 {
21+ ViewData [ "BetaFeatureEnabled" ] = await _featureManager . IsEnabledAsync ( "Beta" ) ;
1822 return View ( ) ;
1923 }
2024
Original file line number Diff line number Diff line change 11using Azure . Identity ;
22using Microsoft . Extensions . Configuration ;
33using Microsoft . Extensions . Configuration . AzureAppConfiguration ;
4+ using Microsoft . FeatureManagement ;
45
56var builder = WebApplication . CreateBuilder ( args ) ;
67var appConfigEndpoint = builder . Configuration [ "AzureAppConfiguration:Endpoint" ] ;
1314builder . Configuration . AddAzureAppConfiguration ( options =>
1415{
1516 options . Connect ( new Uri ( appConfigEndpoint ) , new DefaultAzureCredential ( ) )
17+ . UseFeatureFlags ( featureFlagOptions =>
18+ {
19+ featureFlagOptions . SetRefreshInterval ( TimeSpan . FromSeconds ( 5 ) ) ;
20+ } )
1621 . ConfigureRefresh ( refresh =>
1722 {
1823 refresh . Register ( "TestApp:Settings:Sentinel" , refreshAll : true )
2328// Add services to the container.
2429builder . Services . AddControllersWithViews ( ) ;
2530builder . Services . AddAzureAppConfiguration ( ) ;
31+ builder . Services . AddFeatureManagement ( ) ;
2632builder . Services . Configure < Settings > ( builder . Configuration . GetSection ( "TestApp:Settings" ) ) ;
2733
2834var app = builder . Build ( ) ;
Original file line number Diff line number Diff line change 99 color : @Configuration[" TestApp:Settings:FontColor" ];
1010 font-size : @Configuration[" TestApp:Settings:FontSize" ]px;
1111 }
12+ .feature-flag {
13+ margin-top : 20px ;
14+ padding : 10px ;
15+ border-radius : 5px ;
16+ display : inline-block ;
17+ }
18+ .feature-enabled {
19+ background-color : #d4edda ;
20+ color : #155724 ;
21+ border : 1px solid #c3e6cb ;
22+ }
23+ .feature-disabled {
24+ background-color : #f8d7da ;
25+ color : #721c24 ;
26+ border : 1px solid #f5c6cb ;
27+ }
1228 </style >
1329
14- <h1 >@Configuration ["TestApp:Settings:Message"]</h1 >
30+ <h1 >@Configuration ["TestApp:Settings:Message"]</h1 >
31+
32+ @if (ViewData [" BetaFeatureEnabled" ] is true )
33+ {
34+ <div class =" feature-flag feature-enabled" >
35+ <strong >Beta Feature : </strong > Enabled ✓
36+ </div >
37+ }
Original file line number Diff line number Diff line change @@ -37,6 +37,11 @@ foreach ($entry in $settings.GetEnumerator())
3737 az appconfig kv set -- name $AppConfigName -- key $entry.Key -- value $entry.Value - y -- only- show-errors -- output none | Out-Null
3838}
3939
40+ # Create feature flag
41+ az appconfig feature set -- name $AppConfigName -- feature Beta -- description " Beta feature flag for testing" - y -- only- show-errors -- output none | Out-Null
42+ az appconfig feature enable -- name $AppConfigName -- feature Beta - y -- only- show-errors -- output none | Out-Null
43+ Write-Host " Created and enabled 'Beta' feature flag"
44+
4045$endpoint = " https://$AppConfigName .azconfig.io"
4146dotnet user- secrets init -- project $projectPath | Out-Null
4247dotnet user- secrets set -- project $projectPath ' AzureAppConfiguration:Endpoint' $endpoint | Out-Null
Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ az appconfig kv set --name "${acName}" --key TestApp:Settings:FontSize --value 4
2222az appconfig kv set --name " ${acName} " --key TestApp:Settings:Message --value " Data from Azure App Configuration" -y --only-show-errors -o none
2323az appconfig kv set --name " ${acName} " --key TestApp:Settings:Sentinel --value 1 -y --only-show-errors -o none
2424
25+ # Create feature flag
26+ az appconfig feature set --name " ${acName} " --feature Beta --description " Beta feature flag for testing" -y --only-show-errors -o none
27+ az appconfig feature enable --name " ${acName} " --feature Beta -y --only-show-errors -o none
28+ echo " Created and enabled 'Beta' feature flag"
29+
2530endpoint=" https://${acName} .azconfig.io"
2631dotnet user-secrets init --project " ${project_path} " > /dev/null
2732dotnet user-secrets set --project " ${project_path} " " AzureAppConfiguration:Endpoint" " ${endpoint} " > /dev/null
You can’t perform that action at this time.
0 commit comments