liveBook · Manning

Appsettings.json

As explained in .NET in Action, Second Edition

appsettings.json is a conventional .NET application configuration file containing default JSON settings.

appsettings.json is the conventional .NET application configuration file for default JSON settings. ASP.NET Core loads it before environment-specific configuration and exposes the combined values through IConfiguration. section 3.1 section 13.4.2

Use the configuration hierarchy to separate defaults from deployment-specific values:

  • Place shared or default values in appsettings.json. section 3.1
  • Override matching keys in appsettings.<environment>.json, such as appsettings.Development.json; the environment name comes from an environment variable. section 3.1
  • Allow user secrets, environment variables, and command-line arguments to override earlier values in that order. section 13.4.2
  • Read values through IConfiguration, which combines and flattens the available configuration sources. section 13.4.2

Environment-specific defaults

A base appsettings.json can define shared values, while appsettings.Development.json contains {"EnvironmentName":"Development","RegionName":"My Desk"}. A controller can receive IConfiguration through dependency injection and return those values from a GET endpoint. section 13.4

Listing 13.10 Environment-specific configuration values in appsettings
{
  "EnvironmentName": "Development",
  "RegionName": "My Desk"
}

Inspect a concrete environment-specific appsettings JSON object containing EnvironmentName and RegionName. section 13.4

How .NET in Action, Second Edition covers it

How deep it goes
Explains file loading and override order, demonstrates IConfiguration access, and stops short of detailed configuration binding.
Examples
Uses Development settings, EnvironmentName and RegionName keys, a ConfigController, and TestOverwrite override experiments.
What it assumes
Assumes familiarity with ASP.NET Core applications and introduces configuration sources, environment files, and IConfiguration access.
What you can do after
Operate/configure ASP.NET Core applications by defining defaults, selecting environment files, and verifying overrides through IConfiguration.
How it connects
Connects ASP.NET Core configuration with environment-specific files, IConfiguration, user secrets, environment variables, and command-line arguments.

Also explained in

Compare how 4 books explain appsettings.json →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.