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

后端 未结 10 1485
误落风尘
误落风尘 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:38

    Go with this structure format:

    "MobileConfigInfo": {
        "Values": {
           "appointment-confirmed": "We've booked your appointment. See you soon!",
           "appointments-book": "New Appointment",
           "appointments-null": "We could not locate any upcoming appointments for you.",
           "availability-null": "Sorry, there are no available times on this date. Please try another."
     }
    }
    

    Make your setting class look like this:

    public class CustomSection 
    {
       public Dictionary Values {get;set;}
    }
    

    then do this

    services.Configure((settings) =>
    {
         Configuration.GetSection("MobileConfigInfo").Bind(settings);
    });
    

提交回复
热议问题