Skip to content

Instantly share code, notes, and snippets.

@Vivelin
Created November 16, 2016 15:21
Show Gist options
  • Save Vivelin/d91338556aded3fd489ad713bbac041c to your computer and use it in GitHub Desktop.
Save Vivelin/d91338556aded3fd489ad713bbac041c to your computer and use it in GitHub Desktop.
Vivelin.Environment.Configuration usage example
namespace Vivelin.Environment
{
public class Configuration
{
public Configuration() : this(new JsonConfigurationProvider())
{ }
public Configuration(IConfigurationProvider provider)
{
File = provider;
}
public IConfigurationProvider File { get; }
public string GetSetting(string key)
{
return File.GetSetting(key);
}
public T GetSetting<T>(string key)
{
var value = GetSetting(key);
return (T)Convert.ChangeType(value, typeof(T));
}
public string GetSecret(string key)
{
// Something with DPAPI
}
}
}
using Vivelin.Environment;
public class Preferences : Configuration
{
// Always use JSON
public Preferences() : base(new JsonConfigurationFile())
{ }
public string ClientID => GetSetting("ClientID");
public string ClientSecret => GetSecret("ClientSecret");
public TimeSpan Timeout => GetSetting<TimeSpan>("Timeout");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment