how to get value from appsettings.json

前端 未结 6 697
时光说笑
时光说笑 2020-12-07 12:34
public class Bar
{
    public static readonly string Foo = ConfigurationManager.AppSettings[\"Foo\"];
}

In the .NET Framework 4.x, I can use the

6条回答
  •  隐瞒了意图╮
    2020-12-07 12:42

    1. Add this in AppSettings.json file
      "Swagger": { "Title": "API DEVELOPMENT" }

    2. Then configure that in Startup.cs file

      public Startup(IConfiguration configuration)
      {
          Configuration = configuration;
      }
      
      public IConfiguration Configuration { get; }
      
    3. Next get the value from appsettings.json

      var title = Configuration.GetSection("Swagger:Title").Value;
      
    4. Finally put here

      services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = title, Version = "v1" }); }
      

提交回复
热议问题