Created
November 16, 2016 15:21
-
-
Save Vivelin/d91338556aded3fd489ad713bbac041c to your computer and use it in GitHub Desktop.
Vivelin.Environment.Configuration usage example
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
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 | |
} | |
} | |
} |
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 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