I'm tearing my hair out over a simple problem. I had some settings in my .NET Core 3 app which I thought would be best to move to my appsettings.json file. I followed this guide to do so: https://www.c-sharpcorner.com/article/reading-values-from-appsettings-json-in-asp-net-core/
Further down in the guide, there is a section about how to dependency inject part of the config, which I thought would be a good idea to follow. It says to add the following code to my Startup.cs file in the ConfigureServices method.
services.Configure<ConfigurationProps>(Configuration.GetSection("ApplicationConfiguration"));
When I do this, at first Configuration is unknown, and I cannot import it from any known extension/library. Looking at the recommendations, I can see a NuGet package System.Configuration.ConfigurationManager is available. I therefore tried to install that to see if it would help me. Unfortunately, after doing that, I get the following error from the Configuration object:
An object reference is required for the non-static-field, method, or property 'Configuration.GetSection(string)'
From the guide I've been following, and other documentation I've been able to find online, I don't need to instantiate the Configuration class anywhere.
So, how do I inject my configuration into the services.Configure method following this approach?
EDIT: Added files
appsettings.json:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ApplicationConfiguration": {
"StartingPort": 13000,
"NumberOfConnections": 1
}
}
ConfigurationProps:
namespace ExternalGateway.Models
{
public class ConfigurationProps
{
public int StartingPort { get; set; }
public int NumberOfConnections { get; set; }
}
}