Created
April 15, 2011 13:40
-
-
Save mikeminutillo/921708 to your computer and use it in GitHub Desktop.
For AppHarbor use, this will use the config file by default but fall back to the corresponding environment variable if you use the value {ENV}
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
public interface IConfig | |
{ | |
string Get(string key); | |
} | |
public class Config : IConfig | |
{ | |
public string Get(string key) | |
{ | |
var fromConfig = ConfigurationManager.AppSettings[key]; | |
if (String.Equals(fromConfig, "{ENV}", StringComparison.InvariantCultureIgnoreCase)) | |
{ | |
return Environment.GetEnvironmentVariable(key); | |
} | |
else | |
{ | |
return fromConfig; | |
} | |
} | |
} |
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
public class TheMovieDbService | |
{ | |
private readonly string _apiKey; | |
public TheMovieDbService(IConfig config) | |
{ | |
_apiKey = config.Get("TheMovieDB_API_KEY"); | |
} | |
} |
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
<!-- usage --> | |
<configuration> | |
<appSettings> | |
<add key="TheMovieDB_API_Key" value="{ENV}"/> | |
</appSettings> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment