0
In my application’s web project I have the appsettings.json:
{
"Foo": "Exemplo"
},
And I have a class that reflects that configuration:
public class FooSettings
{
public string Foo { get; set; }
}
In the startup.Cs i read and record to use via dependency injection:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddOptions();
services.Configure<FooSettings>(Configuration.GetSection("Foo")); //lê e injeta dependênc
...
}
Everything’s OK so far. I can get an instance of Foosettings via dependency injection into builders and it works smoothly.
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");
}
Configurationmanager took it straight from the web.config
How to do this in Asp.Net Core 1.1?
Have you tried using a static constructor?
– Rodolpho Sa
@Rodolphosa I didn’t even know it existed. But unfortunately these constructors can’t have parameters.
– Eduardo Moreira