Base solution for your next web application
Open Closed

Read from appsettins json #6898


User avatar
0
digitalcontrol created

How can I read properties from appsettings.json (appsettings.production.json) inside x.Application project services? I need access to connection string beside other variables. I am using dotnet core api + angular solution


3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    You can inject IConfigurationRoot to read appsetting.json

    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.2

  • User Avatar
    1
    ryancyq created
    Support Team

    ideally, you should consider using

    https://aspnetboilerplate.com/Pages/Documents/Startup-Configuration#creating-configuration-for-a-module

    as you won't want every single of your API calls to read from appsettings.json

  • User Avatar
    0
    mdepouw created

    You can inject IConfigurationRoot to read appsetting.json

    That was not giving me the full config. But, I injected IWebHostEnvironment env and then called env.GetAppConfiguration() which gave me a IConfigurationRoot that did have all the config.