Skip to content

Extension methods for adding options services to the DI container using custom bindings.

Notifications You must be signed in to change notification settings

ArvidNyden/CustomConfigurationBinding

Repository files navigation

Custom Configuration Bindings

This is probably not a problem when using regular AppSettings but I found it hard to bind my configuration when using environment variables as well as custom providers as Azure Key Vault or AWS Parameter Store. Their naming conventions just don't mapp to what I want my property names to be.

Framework

The library is built in Net Standard 2.0 but can be downloaded and rebuilt to whatever you need.

How To

Net Core 2.0 Api Example

Startup.cs

services.ConfigureCustom<MyConfiguration>(Configuration);

ValuesController.cs

[HttpGet]
public MyConfiguration Get([FromServices] IOptions<MyConfiguration> conf)
{
    return conf.Value;
}

MyConfiguration.cs

services.ConfigureCustom<MyConfiguration>(Configuration);

public class MyConfiguration
{
    [BindToConfiguration("setting-1")]
    public string FromAppSettings1 { get; set; }

    [BindToConfiguration("setting-2")]
    public string FromAppSettings2 { get; set; }

    public string FromAppSettings3 { get; set; }
}

appsettings.json

{
  "setting-1" :  "Setting1", 
  "setting-2" :  "Setting2", 
  "FromAppSettings3" :  "Setting3"
}

About

Extension methods for adding options services to the DI container using custom bindings.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages