Mid
ASP.NET Core
ASP.NET Core
Using IConfiguration to read settings?
Inject IConfiguration anywhere:
public class MyService {
private readonly string _apiKey;
public MyService(IConfiguration config) {
_apiKey = config["MySettings:ApiKey"];
}
}
You can also access nested settings via config.GetSection("MySettings").
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png