'How to use AddAzureAppConfiguration overloaded method with action parameter
public static IConfigurationBuilder AddConfigurationManagement(
this IConfigurationBuilder builder,
Uri connectionUri,
string tenantId,
string trimPrefix = null,
string refreshKey = null,
string configurationLabel = null,
int cacheExpirationInSeconds = DefaultCacheExpirationInSeconds)
{
builder = builder ?? throw new ArgumentNullException(nameof(builder));
connectionUri = connectionUri ?? throw new ArgumentNullException(nameof(connectionUri));
tenantId = tenantId ?? throw new ArgumentNullException(nameof(tenantId));
//problem here
builder.AddAzureAppConfiguration(options => ConnectTest(options));
//this can work
builder.AddAzureAppConfiguration1(options => ConnectTest(options));
return builder;
}
public static IConfigurationBuilder AddAzureAppConfiguration1(this IConfigurationBuilder configurationBuilder, Action<AzureAppConfigurationOptions> action)
{
if (action != null)
{
AzureAppConfigurationOptions options = new AzureAppConfigurationOptions();
action(options);
}
return configurationBuilder;
}
private static AzureAppConfigurationOptions ConnectTest(AzureAppConfigurationOptions options)
{
return options;
}
//this is the meta function
public static IConfigurationBuilder AddAzureAppConfiguration(this IConfigurationBuilder configurationBuilder, Action<AzureAppConfigurationOptions> action, bool optional = false);
//this is local connectFunction
private static AzureAppConfigurationOptions Connect(
AzureAppConfigurationOptions options,
Uri connectionUri,
string tenantId,
string trimPrefix,
string refreshKey,
string configurationLabel,
int featureManagementCacheExpirationInSeconds)
{
DefaultAzureCredentialOptions defaultAzureCredentialOptions = new DefaultAzureCredentialOptions
{
SharedTokenCacheTenantId = tenantId,
};
options.Connect(connectionUri, new DefaultAzureCredential(defaultAzureCredentialOptions));
AzureAppConfigurationOptionsBuilder(options, trimPrefix, refreshKey, configurationLabel, featureManagementCacheExpirationInSeconds);
return options;
}
Package Microsoft.Extensions.Configuration.AzureAppConfiguration 5.0.0
builder.AddAzureAppConfiguration(options => ConnectTest(options)); builder.AddAzureAppConfiguration1(options => ConnectTest(options));
when use AddAzureAppConfiguration the method ConnectTest doesn't be called But it works when I use AddAzureAppConfiguration1 written by my own What's going on?
Solution 1:[1]
You need to call the Connect method on the options object:
builder.AddAzureAppConfiguration(options =>
options.Connect("<your-connection-string>")
The parameters you're passing into the Connect method are not available on the Connect() method on the AzureAppConfigurationOptions class and it seems you're calling your own local Connect method.
If this is intentional, please provide the code if the Connect() method so we can see if there's any issues there.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rickvdbosch |
