Appsettings.json configuration:
A configuration file is a JSON file, and is a strict JSON file, all attributes need to be added "" quotation marks. is a regular code example:
{"urlstring": { //"URL": "/http//" 27.151.14.174: 8282/apiweb/? " " URL " " http://172.28.40.122:8080/apiweb/? " }}
Defining entities:
Getting the information inside the Appsettings.json needs to define the corresponding model to get the data. Such as:
public class URLString {public string Url {get; set;} }
Read configuration information at startup:
Read the configuration information in the startup Configureservices method. Such as:
Public void configureservices (iservicecollection services) { // ADD Framework services. Services. Addmvc (); // Read configuration information Services. Configure<urlstring> (this. Configuration.getsection ("urlstring"
}
The implementation class calls the implementation of the business, which is accessed through the constructor to get configuration information:
Public classDatacenterappservice:sanfuappservicebase, idatacenterappservice{//Define tired Private ReadOnlyIoptions<urlstring>_appconfiguration; PublicDatacenterappservice (ioptions<UrlString>_appconfiguration) { This. _appconfiguration =_appconfiguration; } Public stringGetstr () {return_appconfiguration.value.url;}}
Read Appsettings.json