In the web project of my application I have appsettings.json :
{
"Foo": "Exemplo"
},
And I have a class that reflects this setting:
public class FooSettings
{
public string Foo { get; set; }
}
In startup.cs I read and log to use via dependency injection:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddOptions();
services.Configure<FooSettings>(Configuration.GetSection("Foo")); //lê e injeta dependênc
...
}
Everything Ok so far. I can get an instance of FooSettings via dependency injection in builders and it works without problems.
The question is: And to get in a static class? In Asp.Net MVC 5 it was like this:
public static class Exemplo
{
private static readonly string Foo = ConfigurationManager.AppSettings.Get("Foo");
}
The ConfigurationManager would fetch direct from web.config
How to do this in Asp.Net Core 1.1?