concept setting in category asp.net

This is an excerpt from Manning's book ASP.NET Core in Action.
As well as demonstrating how to add ExceptionHandlerMiddleware to your middleware pipeline, this listing shows that it’s perfectly acceptable to configure different middleware pipelines depending on the environment when the application starts up. You could also vary your pipeline based on other values, such as settings loaded from configuration.
A setting is any value that changes the behavior of your application. A secret is a special type of setting that contains sensitive data, such as a password, an API key for a third-party service, or a connection string.
The obvious question before we get started is to consider why you need app configuration, and what sort of things you need to configure. You should normally move anything that you can consider a setting or a secret out of your application code. That way, you can easily change these values at runtime, without having to recompile your application.
You might, for example, have an application that shows the locations of your brick-and-mortar stores. You could have a setting for the connection string to the database in which you store the details of the stores, but also settings such as the default location to display on a map, the default zoom level to use, maybe even the locations of the stores, as shown in figure 11.1. You wouldn’t necessarily want to have to recompile your app to tweak these, so you can store them in external configuration sources instead.
In most cases, the default providers will be sufficient. In particular, most templates start with an appsettings.json file, which will contain a variety of settings, depending on the template you choose. This listing shows the default file generated by the ASP.NET Core 1.1 Web template without authentication.
Listing 11.3. Default appsettings.json file created by an ASP.NET Core Web template
{ "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Warning" } } }As you can see, this file only contains settings to control logging to start with, but you can add additional configuration for your app here too.
That brings us to the end of this chapter on configuration. Configuration isn’t glamorous, but it’s an essential part of all apps. The ASP.NET Core configuration provider model handles a wide range of scenarios, letting you store settings and secrets in a variety of locations.
Figure 19.4. Adding a configuration provider that requires configuration. Start by adding configuration providers that you have the details for and build a temporary IConfiguration object. You can use this configuration object to load the settings required by the complex provider, add the provider to your builder, and build the final IConfiguration object using all three providers.
![]()