How to load appsetting.json section into Dictionary in .NET Core?

后端 未结 10 1508
误落风尘
误落风尘 2020-12-05 16:49

I am familiar w/ loading an appsettings.json section into a strongly typed object in .NET Core startup.cs. For example:

public class CustomSection 
{
   publ         


        
10条回答
  •  难免孤独
    2020-12-05 17:36

    The only thing that worked for me (ASP.NET Core 3.0) was to add the following to the ConfigureServices method of Startup.cs:

    services.Configure>(dict => Configuration
        .GetSection("MySectionName")
        .GetChildren()
        .ToList()
        .ForEach(c => dict[c.Key] = c.Value));
    

提交回复
热议问题