Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Latest commit

 

History

History
43 lines (32 loc) · 1.2 KB

File metadata and controls

43 lines (32 loc) · 1.2 KB
sidebar_position sidebar_label
3
Define secrets in configuration

How to define secrets in configuration

Any secrets that are defined in the "RockLib.Secrets" section of the other sources of a configuration builder are added to the SecretsConfigurationSource.

For example, if a configuration builder has JSON file and RockLib secrets sources added:

IConfigurationBuilder builder = new ConfigurationBuilder;

builder.AddJsonFile("appsettings.json");

// Note: No secrets are added directly to the builder in this example, but if
// any had been, they would also be available from the builder's configuration.
builder.AddRockLibSecrets();

And the appsettings.json file defines one or more secrets in its "RockLib.Secrets" section, like this:

{
  "RockLib.Secrets": [
    {
      "Type": "ExampleApp.MyCustomSecret, ExampleApp",
      "Value": {
        "ConfigurationKey": "MyConnectionString"
      }
    }
  ]
}

Then when the builder is built, those secrets will be available from the returned IConfiguration by the value of their ConfigurationKey property.

IConfiguration config = builder.Build();

string myConnectionString = config["MyConnectionString"];