3

I have the following config in appsettings.json

"AvailableThemes": {
    "DefaultThemeKey": "abt",
    "Themes": [
      {
        "ThemeKey": "xc",
        "ThemeTitle": "XC 13"
      },
      {
        "ThemeKey": "abt",
        "ThemeTitle": "Taxis"
        "RegistrationSupported": true,
        "IntroText": "Hello",
      }
    ]
  }
}

I need to be able to override RegistrationSupported in an environment variable so I can deploy the site with registration disabled and enable it when the linked site goes live.

AvailableThemes:Themes:RegistrationSupported

but that won't work because it won't know which item to override. I've tried an indexer like this...

AvailableThemes:Themes[1]:RegistrationSupported

...which didn't work.

Keith Jackson
  • 3,078
  • 4
  • 38
  • 66
  • *didn't work"... in what way? Error message? If so, what was it? What about your code, how are you getting this config? Do you have a class to represent it? What does it look like? – DavidG Mar 06 '18 at 17:52
  • It didn't work - It's to override existing config so it simply didn't do anything. This is a dotnet core config syntax question. The code is irrelevant. – Keith Jackson Mar 06 '18 at 17:57

1 Answers1

5

Found an answer to this almost straight after posting. The Indexer is the right approach but the syntax is wrong.

It should be without square brackets...

AvailableThemes:Themes:1:RegistrationSupported

The full article is here - How to override an ASP.NET Core configuration array setting using environment variables

Keith Jackson
  • 3,078
  • 4
  • 38
  • 66