Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Improve azure app configuration - add support for key prefix

support9e800404aa92
diff --git a/src/Core/Grand.Infrastructure/StartupBase.cs b/src/Core/Grand.Infrastructure/StartupBase.cs
index ddcc41ad4..e39458765 100644
--- a/src/Core/Grand.Infrastructure/StartupBase.cs
+++ b/src/Core/Grand.Infrastructure/StartupBase.cs
@@ -194,11 +194,12 @@ namespace Grand.Infrastructure
/// <param name="services">Collection of service descriptors</param>
/// <param name="configuration">Configuration</param>
/// <param name="typeSearcher">Type searcher</param>
- private static IMvcCoreBuilder RegisterApplication(IServiceCollection services, IConfiguration configuration, ITypeSearcher typeSearcher)
+ private static IMvcCoreBuilder RegisterApplication(IServiceCollection services, IConfiguration configuration,
+ ITypeSearcher typeSearcher)
{
//add accessor to HttpContext
services.AddHttpContextAccessor();
-
+
RegisterConfigurations(services, configuration);
InitDatabase(services, configuration);
@@ -224,7 +225,7 @@ namespace Grand.Infrastructure
options.UseJsonBodyModelBinderProviderInsteadOf<ComplexObjectModelBinderProvider>();
}
});
-
+
return mvcCoreBuilder;
}
@@ -233,8 +234,18 @@ namespace Grand.Infrastructure
var appConfiguration = configuration["Azure:AppConfiguration"];
if (!string.IsNullOrEmpty(appConfiguration))
{
- ((ConfigurationManager)configuration).AddAzureAppConfiguration(appConfiguration);
+ ((ConfigurationManager)configuration).AddAzureAppConfiguration(options =>
+ {
+ options.Connect(appConfiguration);
+ var keyPrefix = configuration["Azure:AppKeyPrefix"];
+ if (!string.IsNullOrEmpty(keyPrefix))
+ {
+ options.Select($"{keyPrefix}:*");
+ options.TrimKeyPrefix($"{keyPrefix}:");
+ }
+ });
}
+
services.StartupConfig<AppConfig>(configuration.GetSection("Application"));
services.StartupConfig<PerformanceConfig>(configuration.GetSection("Performance"));
services.StartupConfig<SecurityConfig>(configuration.GetSection("Security"));
diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.json
index 7bb66e0b6..486b2b99f 100644
--- a/src/Web/Grand.Web/App_Data/appsettings.json
+++ b/src/Web/Grand.Web/App_Data/appsettings.json
@@ -191,8 +191,8 @@
"KeyIdentifier": "", //required when use PersistKeysToAzureKeyVault
//Azure App Configuration
- "AppConfiguration": ""
-
+ "AppConfiguration": "",
+ "AppKeyPrefix": ""
},
"Amazon": {