|
32 | 32 | var services = builder.Services; |
33 | 33 | var configuration = builder.Configuration; |
34 | 34 |
|
| 35 | +var appSettingsSection = configuration.GetSection(nameof(AppSettings)); |
| 36 | +var appSettings = appSettingsSection.Get<AppSettings>(); |
| 37 | + |
35 | 38 | if (!builder.Environment.IsDevelopment()) |
36 | 39 | { |
37 | 40 | services.AddLogging(builder => builder.AddConsole()); |
38 | 41 | } |
39 | 42 |
|
40 | 43 | if (!builder.Environment.IsDevelopment()) |
41 | 44 | { |
42 | | - var azureAppConfigSection = configuration.GetSection(nameof(AppSettings)); |
43 | | - var azureAppConfiguration = azureAppConfigSection.Get<AppSettings>(); |
44 | | - |
45 | 45 | // Load configuration from Azure App Configuration |
46 | 46 | builder.Configuration.AddAzureAppConfiguration( |
47 | 47 | options => |
48 | | - { |
49 | | - options.Connect |
| 48 | + { |
| 49 | + var credentials = new ManagedIdentityCredential(appSettings!.AzureAppConfiguration.IdentityClientID); |
| 50 | + |
| 51 | + options.Connect |
50 | 52 | ( |
51 | | - new Uri(azureAppConfiguration!.AzureAppConfiguration.Endpoint), |
52 | | - new ManagedIdentityCredential(azureAppConfiguration.AzureAppConfiguration.IdentityClientID) |
| 53 | + new Uri(appSettings.AzureAppConfiguration.Endpoint), |
| 54 | + credentials |
53 | 55 | ) |
54 | 56 | .Select(KeyFilter.Any) |
55 | 57 | .Select(KeyFilter.Any, AppSettings.ServiceLabel) |
| 58 | + .ConfigureKeyVault(kv => kv.SetCredential(credentials)) |
56 | 59 | .ConfigureRefresh(refreshOptions => |
57 | 60 | refreshOptions |
58 | | - .Register("AppSettings:Sentinel", AppSettings.ServiceLabel, refreshAll: true) |
| 61 | + .Register("AppSettings:Sentinel", AppSettings.ServiceLabel, refreshAll: true) |
59 | 62 | .SetRefreshInterval(new TimeSpan(0, 0, 15)) |
60 | 63 | ); |
61 | 64 | } |
|
81 | 84 | // uncomment the following line |
82 | 85 | // builder.AddServiceDefaults() |
83 | 86 |
|
84 | | -var appSettingsSection = configuration.GetSection(nameof(AppSettings)); |
85 | | -var appSettings = appSettingsSection.Get<AppSettings>(); |
86 | 87 |
|
87 | 88 | // adds sql server database context |
88 | 89 | services.AddDatabase(configuration); |
|
0 commit comments