Typed Configuration in ASP.NET Core

less than 1 minute read

public class KeyVaultOptions
{
    public string TenantId { get; set; }
    public string ClientId { get; set; }
    public string ClientSecret { get; set; }
}

Then bind the DTO class to the config section.

private static IServiceCollection AddConfigurations(this IServiceCollection services,
    IConfiguration configuration)
{
    services.Configure<KeyVaultOptions>(configuration.GetSection("KeyVault"));
    return services;
}

Categories:

Updated:

Comments