Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@configureappio
Created April 3, 2018 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save configureappio/893f55c1220bb60758a32b61caf7280d to your computer and use it in GitHub Desktop.
Save configureappio/893f55c1220bb60758a32b61caf7280d to your computer and use it in GitHub Desktop.
Example of bridging settings class that takes a validator and and decryptor
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