I making .NET Core console app and need to use env variables like in ASP.NET Core
So I'm using this approach
https://github.com/mattosaurus/BitscryExamples/tree/master/ConsoleAppSettings
Here is my appSettings.json file
{
"ServerUrls": {
"MonitoredDeviceWs": "******",
"MonitoredDeviceBaseFindUri": "*******",
"MonitoredDeviceBaseUploadUri": "*********"
},
"Auth": {
"User": "",
"Password": ""
},
"AppNames": [
"Skype",
"Teams",
"Zoom",
"Cisco"
],
"Other": {
"Space": 0,
"ExecutionFrequency": 30,
"TimerGetInterval": 240
}
}
I need to get MonitoredDeviceWs
for example I try to do it like this
private readonly IConfigurationRoot _config;
public SymphonyCloudCommunicator(IConfigurationRoot config)
{
_config = config;
}
var MonitoredDeviceWs = _config.GetSection("ServerUrls")
But I don't see get method after GetSection
, so I cannot get value like this _configuration.GetSection("ServerUrls").Get<POCO>();
Where am I wrong?
It sounds like you haven't installed the right NuGet Package?
Check for Microsoft.Extensions.Configuration
in your dependencies.
Try this:
private readonly IConfiguration _config;
public SymphonyCloudCommunicator(IConfiguration config)
{
_config = config;
}
the T Get<T>(this IConfiguration configuration)
method is defined in the Microsoft.Extensions.Configuration.ConfigurationBinder
class
Have you installed the microsoft.extensions.configuration.binder package?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.