.NET Core use Configuration to bind to Options with Array

前端 未结 3 1604
傲寒
傲寒 2021-02-12 15:50

Using the .NET Core Microsoft.Extensions.Configuration is it possible to bind to a Configuration to an object that contains an array?

3条回答
  •  眼角桃花
    2021-02-12 16:30

    With recent additions to C# language it is cleaner to use the newer syntax:

    var config = new ConfigurationBuilder()
        .AddInMemoryCollection(new Dictionary
        {
            { "Array:0", "1" },
            { "Array:1", "2" },
            { "Array:2", "3" },
        })
        .Build();
    
    

提交回复
热议问题