Skip to content

Instantly share code, notes, and snippets.

Last active October 7, 2023 07:18
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Allows specifying default configuration values in code while still allowing other sources to override
using Microsoft.Extensions.Configuration.Memory;
var builder = WebApplication.CreateBuilder(args);
{ "request:timeout", "60" }
var app = builder.Build();
// Show example of manually binding from configuration
var config = new Config();
app.MapGet("/", () => config.Timeout);
class Config
public int Timeout { get; set; }
public static class ConfigurationExtensions
public static IConfigurationBuilder AddConfigurationDefaults(this IConfigurationBuilder configurationBuilder, Dictionary<string, string?> defaults)
// Insert at 0 so that other configuraton sources can override the defaults
configurationBuilder.Sources.Insert(0, new MemoryConfigurationSource()
InitialData = defaults
return configurationBuilder;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment