Installation nuget Packages in V 7.0.0
Microsoft.Extensions.Configuration
Microsoft.Extensions.Configuration.Json
Neue Datei appsettings.json im root-Verzeichnis erstellen
In z.B. Program.cs:
public static IConfiguration _conf;
var configuration = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json");
_conf = configuration.Build();
Connection String auslesen:
string connectionString = _conf.GetConnectionString("DefaultConnection")!;
Setting auslesen:
string s = _conf.GetSection("section").Value!;
Verschachtelte Settings auslesen:
"MainSection": {
"SubSection": {
"SubSubSection": "value"
}
string s2 = _conf.GetSection("section:SubSection:SubSubSection").Value!;