Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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