Skip to content

Instantly share code, notes, and snippets.

@mikeminutillo
Created April 15, 2011 13:40
Show Gist options
  • Save mikeminutillo/921708 to your computer and use it in GitHub Desktop.
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}
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;
}
}
}
public class TheMovieDbService
{
private readonly string _apiKey;
public TheMovieDbService(IConfig config)
{
_apiKey = config.Get("TheMovieDB_API_KEY");
}
}
<!-- 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