Skip to content

Instantly share code, notes, and snippets.

@AndyButland
Last active February 10, 2023 14:27
Show Gist options
  • Save AndyButland/d04ff33f5efa3b78ed9aeaaf9b5253a5 to your computer and use it in GitHub Desktop.
Save AndyButland/d04ff33f5efa3b78ed9aeaaf9b5253a5 to your computer and use it in GitHub Desktop.
IConfigurationSection mySettingsSection = builder.Configuration.GetSection("MySettings");
builder.Services.Configure<MySettings>(mySettingsSection);
services.PostConfigure<MySettings>(options =>
{
if(!options.MyOptions.Any(x => x.Alias == "itemOne"))
{
options.MyOptions.Add(new MyOption { Alias = "itemOne", Value = 0 });
}
if(!options.MyOptions.Any(x => x.Alias == "itemTwo"))
{
options.MyOptions.Add(new MyOption { Alias = "itemTwo", Value = 0 });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment