To setup dotnet secrets, you run the dotnet user-secrets init
command. This readies the project for the use of dotnet secrets. To add a secret, you use the dotnet user-secrets set {Name} "{Value}"
. You must redo this for every project in which you are using the secret. Simply add the name of the secret and the value to create an secret. it is stored locally in %appdata%
. On GitHub it is possible to use Environment variables to fill in the gaps left by dotnet secrets.
In the underlying code is a example of how to apply dotnet secrets. To fetch a secret this underlying piece of code is used. Here we create a ConfigurationBuilder and fill it with the secrets per project/class. From there it is as easy as querying the list for the right value.