Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use the .NET Core Options Pattern with envorinment variables that contain periods?

I have a .NET Core console application setup with all the packages to use the Options pattern. Settings coming from my appsettings.json work just fine, but my environment variables contain period characters like:

App.Setting.Value1 = "someval"
App.Setting.Val2 = "somethingelse"

I am trying to strongly type my settings using the Options pattern, but C# property names can't have period characters in them.

How do I configure during DI init time for this?

like image 676
Paul Duer Avatar asked Sep 13 '25 23:09

Paul Duer


1 Answers

use custom attribute binder:

  public class MySetting{
       [ConfigurationKeyName(Name="App.Settings.Value1")]
       public string Value1{get;set;}
       [ConfigurationKeyName(Name="App.Settings.Value2")]
       public string Value2{get;set;}
    }

source: https://github.com/dotnet/runtime/issues/36010

like image 107
phiree Avatar answered Sep 16 '25 13:09

phiree