Created
April 2, 2018 15:38
-
-
Save configureappio/6de2917887f97e86edf5189ae24af701 to your computer and use it in GitHub Desktop.
Example of injecting a decyption service and settings validator into the settings bridge
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 void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc(); | |
services.AddOptions(); | |
services.Configure<MyAppSettings>(Configuration.GetSection("MyAppSettings")); | |
services.AddSingleton(Configuration); | |
// In a real implementation, you would have a factory here to get the password and salt securely | |
// from somewhere such as Azure Key Vault, Environmental variable / another json setting (obfuscated in some way) | |
services.AddSingleton( x => new CryptoFactory().Create<AesManaged>("Password", "Salt")); | |
services.AddSingleton<ISettingsDecrypt, SettingsDecryptor>(); | |
services.AddSingleton<ISettingsValidator, SettingsValidator>(); | |
services.AddScoped<IAppSettingsResolved, MyAppSettingsBridge>(); | |
// add the other interfaces implemented by MyAppSettingsBridge to allow for resolution by those interfaces (interface segregation) | |
services.AddScoped<IAppSettings>(provider => provider.GetService<IAppSettingsResolved>()); | |
services.AddScoped<ISqlConnectionSettings>(provider => provider.GetService<IAppSettingsResolved>()); | |
services.AddScoped<IOracleConnectionSettings>(provider => provider.GetService<IAppSettingsResolved>()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment