.NET Developer interview question

How do you manage configuration in .NET?

Layer .NET configuration from checked-in defaults, environment-specific providers, and an external secret store; bind validated options, fail fast on missing required values, and avoid environment branches scattered through business code.

Direct answer

What a strong answer covers

How it works

Configuration is a layered set of providers where later sources override earlier ones: appsettings.json for defaults, appsettings.{Environment}.json for stage-specific values, environment variables and command-line arguments for deployment, and a secret store such as Azure Key Vault or the user-secrets tool in development. Strongly typed options classes bind sections and are validated at startup with ValidateDataAnnotations and ValidateOnStart, so a missing connection string fails the deploy rather than the first request. Business code depends on IOptions of a specific class, never on the environment name.

Example

A payments service binds PaymentOptions with a required MerchantId and a Url validated as absolute; in production the values come from Key Vault through a provider, in CI from environment variables, and locally from user secrets, with the same code path. A deploy that forgot the Key Vault reference failed at startup with a clear validation message instead of a null reference on the first payment.

Common mistakes

  • Committing secrets in appsettings.json because it was convenient locally.
  • Branching on the environment name inside services instead of configuring behaviour.
  • Reading IConfiguration strings ad hoc throughout the code with no validation.

A useful answer structure

Answer from your own work.

Do not memorise a script: use only examples you can explain honestly in follow-up questions.

Practise this answer with MiraHint

Open the desktop workspace and rehearse a clear answer in your own words.

Download MiraHint
.NET Developer interview questions