RickStrahl / Westwind.Utilities

A general purpose utility and helper library for .NET development

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to override settings with Secrets?

OzBob opened this issue · comments

commented

Can a WestWind Utilities application settings mapping be overridden by a Secrets.json?

The App Secret Docs show how to use a naming convention when mapping to a POCO.

"Application:ApplicationName": "secretTestAppName"

Is there a naming convention to set a secret so that it will override the setting in the appsettings.json?

No that's not supported.

Frankly if you want the inherited model for configuration you should just use the .NET Core configuration system directly. It provides most of the features that the Configuration class provides (main thing missing is auto-write and easy way to write/update keys).

I've thought about extending this class to provide some of these features, but then I'm not sure that that's really necessary. Basically if I need writable keys I use my lib and just have separate files (sometimes that's quite useful actually). Otherwise - mostly for ASP.NET apps I just use the built-in configuration.

commented

thx.
I'll use the .NetCore config system that supports items being overwritten in Dev using 'User secrets' or in Prod via Application Settings. I like the appsettings JSON deserialized into an C# object, so I'll use that for non-secret settings.

commented

for posterity i'll post my findings. The settings are overridden by user secrets if you use ":" to separate every level
e.g.
image

usersecrets.json

{
  "Application:JwtToken:Issuer": "https://secretIssuer.com",
  "Application:ApplicationName": "secretname"  
}

will override a setting in an appsettings.Development.json of:

{
  "Application": {
    "JwtToken": {
      "Issuer": "https://testIssuer.com"