@@ -39,7 +41,7 @@
else
{
- THERE ARE NO RESULTS THAT MATCH YOUR SEARCH
+ @Model.SettingsModel.NoResultsMessage
}
diff --git a/src/Web/Pages/Index.cshtml.cs b/src/Web/Pages/Index.cshtml.cs
index f41ba30..701a301 100644
--- a/src/Web/Pages/Index.cshtml.cs
+++ b/src/Web/Pages/Index.cshtml.cs
@@ -1,16 +1,19 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.eShopWeb.Web.Services;
using Microsoft.eShopWeb.Web.ViewModels;
+using Microsoft.Extensions.Options;
namespace Microsoft.eShopWeb.Web.Pages;
public class IndexModel : PageModel
{
private readonly ICatalogViewModelService _catalogViewModelService;
+ public SettingsViewModel SettingsModel { get; }
- public IndexModel(ICatalogViewModelService catalogViewModelService)
+ public IndexModel(ICatalogViewModelService catalogViewModelService, IOptionsSnapshot options)
{
_catalogViewModelService = catalogViewModelService;
+ SettingsModel = options.Value;
}
public required CatalogIndexViewModel CatalogModel { get; set; } = new CatalogIndexViewModel();
diff --git a/src/Web/Pages/_ViewImports.cshtml b/src/Web/Pages/_ViewImports.cshtml
index 2bf31ee..d85ca5f 100644
--- a/src/Web/Pages/_ViewImports.cshtml
+++ b/src/Web/Pages/_ViewImports.cshtml
@@ -7,3 +7,4 @@
@using Microsoft.eShopWeb.Infrastructure.Identity
@namespace Microsoft.eShopWeb.Web.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
+@addTagHelper *, Microsoft.FeatureManagement.AspNetCore
diff --git a/src/Web/Program.cs b/src/Web/Program.cs
index 9761361..7e37730 100644
--- a/src/Web/Program.cs
+++ b/src/Web/Program.cs
@@ -18,15 +18,20 @@
using Microsoft.eShopWeb.Web.Configuration;
using Microsoft.eShopWeb.Web.HealthChecks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
+using Microsoft.eShopWeb.Web.Pages;
+using Microsoft.FeatureManagement;
+using Microsoft.IdentityModel.Tokens;
var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddConsole();
-if (builder.Environment.IsDevelopment() || builder.Environment.EnvironmentName == "Docker"){
+if (builder.Environment.IsDevelopment() || builder.Environment.EnvironmentName == "Docker")
+{
// Configure SQL Server (local)
Microsoft.eShopWeb.Infrastructure.Dependencies.ConfigureServices(builder.Configuration, builder.Services);
}
-else{
+else
+{
// Configure SQL Server (prod)
var credential = new ChainedTokenCredential(new AzureDeveloperCliCredential(), new DefaultAzureCredential());
builder.Configuration.AddAzureKeyVault(new Uri(builder.Configuration["AZURE_KEY_VAULT_ENDPOINT"] ?? ""), credential);
@@ -93,6 +98,40 @@
config.Path = "/allservices";
});
+// Bind configuration "eShopWeb:Settings" section to the Settings object
+builder.Services.Configure(builder.Configuration.GetSection("eShopWeb:Settings"));
+// Initialize useAppConfig parameter
+var useAppConfig = false;
+Boolean.TryParse(builder.Configuration["UseAppConfig"], out useAppConfig);
+// Add Azure App Configuration middleware to the container of services.
+builder.Services.AddAzureAppConfiguration();
+builder.Services.AddFeatureManagement();
+// Load configuration from Azure App Configuration
+if (useAppConfig)
+{
+ builder.Configuration.AddAzureAppConfiguration(options =>
+ {
+ var appConfigEndpoint = builder.Configuration["AppConfigEndpoint"];
+
+ if (String.IsNullOrEmpty(appConfigEndpoint))
+ {
+ throw new Exception("AppConfigEndpoint is not set in the configuration. Please set AppConfigEndpoint in the configuration.");
+ }
+
+ options.Connect(new Uri(appConfigEndpoint), new DefaultAzureCredential())
+ .ConfigureRefresh(refresh =>
+ {
+ // Default cache expiration is 30 seconds
+ refresh.Register("eShopWeb:Settings:NoResultsMessage").SetCacheExpiration(TimeSpan.FromSeconds(10));
+ })
+ .UseFeatureFlags(featureFlagOptions =>
+ {
+ // Default cache expiration is 30 seconds
+ featureFlagOptions.CacheExpirationInterval = TimeSpan.FromSeconds(10);
+ });
+ });
+}
+
// blazor configuration
var configSection = builder.Configuration.GetRequiredSection(BaseUrlConfiguration.CONFIG_NAME);
builder.Services.Configure(configSection);
@@ -115,6 +154,12 @@
var app = builder.Build();
+if (useAppConfig)
+{
+ // Use Azure App Configuration middleware for dynamic configuration refresh.
+ app.UseAzureAppConfiguration();
+}
+
app.Logger.LogInformation("App created...");
app.Logger.LogInformation("Seeding Database...");
diff --git a/src/Web/Properties/launchSettings.json b/src/Web/Properties/launchSettings.json
index 4dfb1e9..edbd81b 100644
--- a/src/Web/Properties/launchSettings.json
+++ b/src/Web/Properties/launchSettings.json
@@ -22,7 +22,10 @@
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
+ "ASPNETCORE_ENVIRONMENT": "Development",
+ "AZURE_TENANT_ID": "{azure-tenant-id}",
+ "AZURE_CLIENT_ID": "{azure-client-id}",
+ "AZURE_CLIENT_SECRET": "{azure-client-secret}"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
diff --git a/src/Web/Web.csproj b/src/Web/Web.csproj
index 6ed273b..0598e42 100644
--- a/src/Web/Web.csproj
+++ b/src/Web/Web.csproj
@@ -1,6 +1,6 @@
-
+
enable
enable
Microsoft.eShopWeb.Web
@@ -29,11 +29,13 @@
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
+
diff --git a/src/Web/appsettings.json b/src/Web/appsettings.json
index c2bc659..9cf1fc4 100644
--- a/src/Web/appsettings.json
+++ b/src/Web/appsettings.json
@@ -16,5 +16,13 @@
"System": "Warning"
},
"AllowedHosts": "*"
- }
+ },
+
+ "eShopWeb": {
+ "Settings": {
+ "NoResultsMessage": "THERE ARE NO RESULTS THAT MATCH YOUR SEARCH"
+ }
+ },
+ "UseAppConfig": false,
+ "AppConfigEndpoint": ""
}