Created
April 3, 2018 07:36
-
-
Save configureappio/893f55c1220bb60758a32b61caf7280d to your computer and use it in GitHub Desktop.
Example of bridging settings class that takes a validator and and decryptor
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 MyAppSettingsBridge : IAppSettingsResolved | |
{ | |
private readonly IOptions<MyAppSettings> _appSettings; | |
private readonly ISettingsDecrypt _decryptor; | |
public MyAppSettingsBridge(IOptionsSnapshot<MyAppSettings> appSettings, ISettingsDecrypt decryptor, ISettingsValidator validator) { | |
_appSettings = appSettings ?? throw new ArgumentNullException(nameof(appSettings)); | |
_decryptor = decryptor ?? throw new ArgumentException(nameof(decryptor)); | |
if (validator == null) throw new ArgumentNullException(nameof(validator)); | |
if (!validator.TryValidate(appSettings.Value, out var validationException)) | |
{ | |
throw validationException; | |
} | |
} | |
public string ApplicationName => _appSettings.Value.ApplicationName; | |
public string SqlConnectionSting => _decryptor.Decrypt("Sql", _appSettings.Value.Secrets); | |
public string OracleConnectionSting => _decryptor.Decrypt("Oracle", _appSettings.Value.Secrets); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment