In the particular project I am working on, I am using the same pattern as I use in other projects successfully. However, with this one I am unable to successfully use IConfiguration's IsSettingEnabled.
Setup.cs
class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
}
public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
var context = builder.GetContext();
builder.ConfigurationBuilder
.AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.{context.EnvironmentName}.json"), optional: true, reloadOnChange: false);
}
}
appsettings.Development.json
{
"ConfigName": "myconfig"
}
TheFunction.cs
public class TheFunction
{
private IConfiguration _configuration = null;
public TheFunction(IConfiguration configuration)
{
_configuration = configuration;
}
[FunctionName("TheFunction")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
string configName = "ConfigName";
string configValue = _configuration[configName];
bool configValueExists = _configuration.IsSettingEnabled(configName);
}
When the code runs, configValue is "myconfig" as expected. However, configValueExists is False.
Is there something I missed in the setup? It's like whatever Dictionary IsSettingEnabled is using has not been built, and that the [] operator uses a different method of getting the value.
Based on the source code Azure's
IsSettingEnabledchecks if settings value is not empty and can be interpreted as true boolean:And
"myconfig"definitely can not be interpreted as truthful in this context.