-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more changes to azure app config connection
hopefully this is more reliable
- Loading branch information
1 parent
7174ec0
commit b00cdd2
Showing
6 changed files
with
62 additions
and
37 deletions.
There are no files selected for viewing
62 changes: 28 additions & 34 deletions
62
...ucture/AzureAppConfigurationExtensions.cs → ...r.Chat/AzureAppConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,28 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Jordnaer.Shared.Infrastructure; | ||
|
||
public static class AzureAppConfigurationExtensions | ||
{ | ||
public static WebApplicationBuilder AddAzureAppConfiguration(this WebApplicationBuilder builder, string configKey = "ConnectionStrings:AppConfig") | ||
{ | ||
string? connectionString = builder.Configuration[configKey]; | ||
if (connectionString is null) | ||
{ | ||
return builder.Environment.IsDevelopment() | ||
? builder | ||
: throw new InvalidOperationException("Connection string 'AppConfig' not found."); | ||
} | ||
|
||
builder.Services.AddAzureAppConfiguration(); | ||
builder.Configuration.AddAzureAppConfiguration(options => | ||
options.Connect(connectionString) | ||
// Load all keys that have no label | ||
.Select("*") | ||
// Configure to reload builder if the registered sentinel key is modified | ||
.ConfigureRefresh(refreshOptions => | ||
{ | ||
refreshOptions.Register("Sentinel", refreshAll: true); | ||
refreshOptions.SetCacheExpiration(TimeSpan.FromMinutes(5)); | ||
}) | ||
.UseFeatureFlags(flagOptions => flagOptions.CacheExpirationInterval = TimeSpan.FromMinutes(3))); | ||
|
||
return builder; | ||
} | ||
} | ||
namespace Jordnaer.Chat; | ||
|
||
public static class AzureAppConfigurationExtensions | ||
{ | ||
public static WebApplicationBuilder AddAzureAppConfiguration(this WebApplicationBuilder builder) | ||
{ | ||
string? connectionString = builder.Configuration.GetConnectionString("AppConfig") ?? builder.Configuration["appconfig"]; | ||
if (connectionString is null) | ||
{ | ||
throw new InvalidOperationException("Failed to find connection string to Azure App Configuration. Keys checked: 'ConnectionStrings:AppConfig' and 'appconfig'"); | ||
} | ||
|
||
builder.Services.AddAzureAppConfiguration(); | ||
builder.Configuration.AddAzureAppConfiguration(options => | ||
options.Connect(connectionString) | ||
// Load all keys that have no label | ||
.Select("*") | ||
// Configure to reload builder if the registered sentinel key is modified | ||
.ConfigureRefresh(refreshOptions => | ||
{ | ||
refreshOptions.Register("Sentinel", refreshAll: true); | ||
refreshOptions.SetCacheExpiration(TimeSpan.FromMinutes(5)); | ||
}) | ||
.UseFeatureFlags(flagOptions => flagOptions.CacheExpirationInterval = TimeSpan.FromMinutes(3))); | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/web/Server/Extensions/AzureAppConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Jordnaer.Server.Extensions; | ||
|
||
public static class AzureAppConfigurationExtensions | ||
{ | ||
public static WebApplicationBuilder AddAzureAppConfiguration(this WebApplicationBuilder builder) | ||
{ | ||
string? connectionString = builder.Configuration.GetConnectionString("AppConfig"); | ||
if (connectionString is null) | ||
{ | ||
throw new InvalidOperationException("Failed to find connection string to Azure App Configuration. Keys checked: 'ConnectionStrings:AppConfig'"); | ||
} | ||
|
||
builder.Services.AddAzureAppConfiguration(); | ||
builder.Configuration.AddAzureAppConfiguration(options => | ||
options.Connect(connectionString) | ||
// Load all keys that have no label | ||
.Select("*") | ||
// Configure to reload builder if the registered sentinel key is modified | ||
.ConfigureRefresh(refreshOptions => | ||
{ | ||
refreshOptions.Register("Sentinel", refreshAll: true); | ||
refreshOptions.SetCacheExpiration(TimeSpan.FromMinutes(5)); | ||
}) | ||
.UseFeatureFlags(flagOptions => flagOptions.CacheExpirationInterval = TimeSpan.FromMinutes(3))); | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters