Now how would we load this into a settings object? .NET doesn’t support this kind of class natively. Fortunately, it isn’t hard to set this up with an extension method. Let’s create the settings class:

public class SourceSettings: Dictionary<string, string>
{
}

Next, we’ll add a static extension method that takes an IConfigurationSection and loads it into the IServiceCollection. This extension method will do the heavy lifting for us.

If we can do a Dictionary<string, string>, can we do a List<string>-type of settings as well? It turns out the answer is: yes! I don’t have a good use-case for this, but it is nice to know that there are options!