Wednesday, September 12, 2018

How to map appsetting.json value with startup.cs in .Net Core

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

Kashmir 370 and 35A : The Wound of india

क्या है जम्मू-कश्मीर में लागू धारा 370,35A पूर्ण विवरण Know about 370 act in Jammu एक बार फिर से राजनीति गलियारे में धारा 370,35A को ल...