In order to read the settings from the application we normally point to the lovely documentation, but that only deals with XML and plain Text files…
Does anyone ever needed to extract the application settings from a json file like the appsettings.json
?
using the current support as
var appSettings =
new ServiceStack.Configuration.TextFileSettings(
"../appsettings.json".MapHostAbsolutePath());
I only get the first char {
where my appsettings.json
file is
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Verbose",
"System": "Information",
"Microsoft": "Information"
}
},
"AppSettings": {
"Cache": {
"TimeSpan": 5
},
"Algolia": {
"AppId": "XXXXX",
"ApiKey": "xxxxxxx",
"HitsPerPage": 50
},
"Credentials": {
"BaseUri": "http://api.xxxxxxx.dk",
"Username": "api",
"Password": "xxxxxxxx",
"ImageBaseUri": "https://dynassets.xxx.dk"
},
"Smtp": {
"Host": "127.0.0.1",
"Port": 25,
"Username": "",
"Password": ""
},
"UrlRedirect": {
"MainSite": {
"Host": "localhost",
"BaseUrl": "http://localhost:26892/"
},
"PortalSite": {
"Host": "localhost",
"BaseUrl": "http://localhost:26892/"
},
"AlternativeMainSite": {
"Host": "gogift.demo.kodexe.se",
"BaseUrl": "http://demo.goxxxx.sf2/"
},
"UnsupportedHostUrl": "http://localhost:26892/?error=unknowndomain"
}
}
}
would be nice to simple do:
var appSettings = new JsonFileSettings("../appsettings.json".MapHostAbsolutePath());
_appId = appSettings.Get<string>("Algolia.AppId");
_apiKey = appSettings.Get<string>("Algolia.ApiKey");
_hitsPerPage = appSettings.Get<int>("Algolia.HitsPerPage");
Thanks.
P.S. I know we can use Microsoft.AspNet.Builder.IApplicationBuilder
to extract and use the applications, but I really wanted to stick with SStack.