dotnet user-secrets init
dotnet user-secrets set "Redis:ConnectionString" "12345"
IConfiguration configuration;
// with get
Configuration.GetSection("Redis")
// indexed key style
Configuration["Redis:ConnectionString"]
var moviesConfig = Configuration.GetSection("Redis").Get<RedisOptions>();
class RedisOptions {
public string ConnectionString {get; set;}
//...
}
// binding configuration section to runtime object
services.Configure<RedisOptions>("Redis");
// Accessing anywhere in constructor through DependencyInjection
class Controller {
public Controller(IOptions<JwtSettingsDto> jwtOptions)
{
//...
}
}
Configuration.GetConnectionString("DefaultConnectionString");
Separate document available here