In this blog, I will explain, how to get appsetting.json value in Startup.cs file.
appsettings.json
{
"ApplicationValue": {
"filePath": "~/tempData/test.json"
}
}
Startup.cs
public class Startup
{
public IConfigurationRoot Configuration { get; set; }
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json")
Configuration = builder.Build();
}
public void ConfigureServices(IServiceCollection services)
{
services.Configure<ApplicationSettings>
(Configuration.GetSection("ApplicationValue"));
}
public void Configure(IApplicationBuilder app,
IHostingEnvironment env, ILoggerFactory loggerFactory)
{
var applicationSettings = Configuration.Get<ApplicationValue>("ApplicationValue");
}
}
No comments:
Post a Comment