What would be the best way to combine and bind variables from both appsettings and environment variables into one model? Using dotnet7
E.g.
public class MyOptions
{
public const string SectionName = "MySettings";
// this property should be set from appsettings.json
public string Address { get; set; }
// this property should be set from environment variable
public int TestNumber { get; set; }
]
Then in program.cs
builder.Services
.AddOptions<MyOptions>()
.Bind(config.GetSection(MyOptions.SectionName))
.ValidateOnStart();
Will bind the part from appsettings section but how can I solve the environment variable. It works by seperating them into two different models and "duplicate" the AddOptions but would rather keep it into one model rather than two.
As mention, seperating them into two different models works but haven't been able to figure out the way to combine them.
Fairly new to csharp so be gentle :)