C# Interview Question #164
What is configuration in ASP.NET Core?
ASP.NET Core, DI & Middleware Senior Advanced
Quick Interview Answer
ASP.NET Core configuration combines settings from providers such as appsettings.json, environment-specific JSON files, environment variables, command-line arguments, user secrets during development, and external configuration systems.
Detailed Explanation
ASP.NET Core configuration combines settings from providers such as appsettings.json, environment-specific JSON files, environment variables, command-line arguments, user secrets during development, and external configuration systems.
Configuration values can be accessed through IConfiguration, but strongly typed options are usually preferable for groups of related settings.
Sensitive production secrets should not be committed to source-controlled configuration files. They should come from secure environment or secret-management systems.
Code Example
builder.Services.Configure<EmailOptions>(
builder.Configuration.GetSection("Email"));
public class EmailOptions
{
public string Host { get; set; } = string.Empty;
public int Port { get; set; }
}