Last active
October 13, 2016 12:23
-
-
Save stuartleeks/e356956ebf5f1e38718c to your computer and use it in GitHub Desktop.
CustomConfigurationManager - pre ASP.NET 5 helper for working with environment variables for app settings
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
using System; | |
using System.Configuration; | |
public static class CustomConfigurationManager | |
{ | |
private static CustomAppSettings _appSettings = new CustomAppSettings(); | |
public static CustomAppSettings AppSettings { get { return _appSettings; } } | |
} | |
public class CustomAppSettings | |
{ | |
const string AppSettingsPrefix = "APPSETTING_"; | |
public string AppPrefix { get; set; } | |
public string Get(string key) | |
{ | |
return this[key]; | |
} | |
public string this[string key] | |
{ | |
get | |
{ | |
string fullKey; | |
if (!string.IsNullOrEmpty(AppPrefix)) | |
{ | |
fullKey = AppPrefix + "_" + key; | |
} | |
else | |
{ | |
fullKey = key; | |
} | |
string value = Environment.GetEnvironmentVariable(AppSettingsPrefix + fullKey) | |
?? Environment.GetEnvironmentVariable(fullKey) | |
?? ConfigurationManager.AppSettings[fullKey] | |
?? ConfigurationManager.AppSettings[key]; | |
return value; | |
} | |
} | |
} |
Does CloudConfigurationManager
check environment variables? IIRC it checks the role config for cloud services
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@stuartleeks could you perhaps use
CloudConfigurationManager
instead? Is there anything am I underestimating in your implementation please? Thx 🍻