Defining a configuration setting in an Azure ServiceConfiguration (.cscfg
) is compelling because I can then change the value within the Azure portal.
However, as discussed here Microsoft.WindowsAzure.CloudConfigurationManager.GetSettings("Foo")
will fall back to looking for a <appSettings>
value in the app.config.
Is it possible to have it fallback to a Settings.setting
file instead?
I could create a method like this, but is there a better/built-in way?
public T GetSetting<T>(string name, T defaultValue = null)
{
return
!RoleEnvironment.IsAvailable
//we could be in a non azure emulated environment (ie unit test)
? defaultValue
: RoleEnvironemt.GetConfigurationSettingValue(name)
??
//in case no value is specified in .cscfg or <appSettings>
defaultValue;
}
And then have to call it like:
var settings = GetSetting("Example", Properties.Settings.Default.Example);
But this is a pain that I have to specify the "Example"
string parameter