Skip to content

Commit

Permalink
Improve azure app configuration - add support for key prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
support committed Feb 26, 2024
1 parent 588dc18 commit 9e80040
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 15 additions & 4 deletions src/Core/Grand.Infrastructure/StartupBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,12 @@ private static void AddMassTransitRabbitMq(IServiceCollection services, IConfigu
/// <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);
Expand All @@ -224,7 +225,7 @@ private static IMvcCoreBuilder RegisterApplication(IServiceCollection services,
options.UseJsonBodyModelBinderProviderInsteadOf<ComplexObjectModelBinderProvider>();
}
});

return mvcCoreBuilder;
}

Expand All @@ -233,8 +234,18 @@ private static void RegisterConfigurations(IServiceCollection services, IConfigu
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"));
Expand Down
4 changes: 2 additions & 2 deletions src/Web/Grand.Web/App_Data/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@
"KeyIdentifier": "", //required when use PersistKeysToAzureKeyVault

//Azure App Configuration
"AppConfiguration": ""

"AppConfiguration": "",
"AppKeyPrefix": ""
},
"Amazon": {

Expand Down

0 comments on commit 9e80040

Please sign in to comment.