Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1.67 KB

README.md

File metadata and controls

39 lines (30 loc) · 1.67 KB

SapientGuardian.ConfigureAll

Windows Build status
Linux/OSX Build Status
NuGet Package

Description

ConfigureAll is a library to make using the Options configuration pattern easier. Just add the ConfigurationObject attribute and ConfigureAll!

How to use it

  1. 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; }
        }
    }
  2. Call ConfigureAll in your ConfigureServices method
    using Microsoft.Extensions.Options;
    
    public IConfiguration Configuration { get; }
    
    public void ConfigureServices(IServiceCollection services)
        {            
            services.AddOptions();
    
            services.ConfigureAll(this.GetType().GetTypeInfo().Assembly, Configuration);
        }
    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.