| sidebar_position | 2 |
|---|---|
| sidebar_label | Add secrets to configuration builder |
To add secrets to an IConfigurationBuilder, call the AddRockLibSecrets extension method on the builder, optionally passing an Action<SecretsConfigurationSource> for configuring the source.
IConfigurationBuilder builder = new ConfigurationBuilder();
builder.AddRockLibSecrets(source =>
{
// TODO: configure source
});This extension method returns an ISecretsConfigurationBuilder, which has a AddSecret method for adding secrets.
IConfigurationBuilder builder = new ConfigurationBuilder();
ISecretsConfigurationBuilder secretsBuilder = builder.AddRockLibSecrets();
secretsBuilder.AddSecret(new MyCustomSecret(configurationKey: "MyConnectionString"));Implementations of ISecret, such as AwsSecret, have extension methods for simplifying the adding of a secret:
IConfigurationBuilder builder = new ConfigurationBuilder();
ISecretsConfigurationBuilder secretsBuilder = builder.AddRockLibSecrets();
secretsBuilder.AddAwsSecret("MyConnectionString", "MySecretId", "MySecretKey");The SecretsConfigurationSource defines several options:
Secrets- This property defines the secrets that the source provides.
- The
ConfigurationBuilderclass adds to this property when itsAddSecretmethod is called.
OnSecretException- This callback is invoked whenever the
GetValue()method of anISecretthrows an exception.
- This callback is invoked whenever the
ReloadMilliseconds- This property defines how often the configuration provider reloads its data. Specify
Timeout.Infiniteor call theDisableReload()method to disable reloading.
- This property defines how often the configuration provider reloads its data. Specify