ConfigureAll is a library to make using the Options configuration pattern easier. Just add the ConfigurationObject attribute and ConfigureAll!
- Add the ConfigurationObject attribute on your configuration objects indicating the name of the key in your configuration that maps to the object
using SapientGuardian.ConfigureAll; namespace ConfigureAllTests { [ConfigurationObject("TestKey")] public class TestConfigurationObject { public string TestValue { get; set; } } }
- Call ConfigureAll in your ConfigureServices method
If your configuration objects are stored in a different assembly than the one containing your ConfigureServices method, be sure to specify that in the first parameter to ConfigureAll.
using Microsoft.Extensions.Options; public IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { services.AddOptions(); services.ConfigureAll(this.GetType().GetTypeInfo().Assembly, Configuration); }