Appconfiguration: Configuration with Integer Array value

Created on 15 Jan 2020  路  4Comments  路  Source: Azure/AppConfiguration

How do we store integer array as configuration value for example:
StatusCodes: 409,412,500

I did see one option is to include index and have three entries (like below)
StatusCodes:0 409
StatusCodes:1 412
StatusCodes:3 500

But this is going to be very hard to maintain. Is there any other better way to store the array in one configuration?

question

Most helpful comment

.NET Core Configuration is designed to be source format agnostic. It implements own default binding rules and therefore the syntax for array you pointed out.

By design Azure AppConfiguration Service (and most externalized configuration providers) avoid preferred client bindings. The lowest common denominator is key-value pair (the same is also valid if you try to use Environment variables as configuration settings in .NET Core). The reason for that is the ability to provide configuration for different platforms/frameworks. It's balanced approach to share Configuration to multiple services based on different technology.

In general I prefer my configuration to be described as first class citizen. I agree with you to specify list of values in CSV form, rather than .NET Core specific syntax - that makes the config more portable long term. To bind that into .NET Core configuration, you may want to take a look at IOptions pattern. What I have done in the past is to provide read-only property that maps the CSV into a collection (even allowing type safe representation). For example:

public class MyOptions
{
        private string _statusCodes;

        public IEnumerable<int> StatusCodesList { get; private set; }

        public string StatusCodes {    // CSV
            get { 
                return _statusCodes; 
            }
            set {
                StatusCodesList = value.Split(',').Select(s => int.Parse(s.Trim()));
                _statusCodes = value;
            }
        }    
}

All 4 comments

That depends indeed on the client binding you are choosing. Are you asking for .NET Core Configuration?

@drago-draganov Yes, this is for .Net Core Configuration

.NET Core Configuration is designed to be source format agnostic. It implements own default binding rules and therefore the syntax for array you pointed out.

By design Azure AppConfiguration Service (and most externalized configuration providers) avoid preferred client bindings. The lowest common denominator is key-value pair (the same is also valid if you try to use Environment variables as configuration settings in .NET Core). The reason for that is the ability to provide configuration for different platforms/frameworks. It's balanced approach to share Configuration to multiple services based on different technology.

In general I prefer my configuration to be described as first class citizen. I agree with you to specify list of values in CSV form, rather than .NET Core specific syntax - that makes the config more portable long term. To bind that into .NET Core configuration, you may want to take a look at IOptions pattern. What I have done in the past is to provide read-only property that maps the CSV into a collection (even allowing type safe representation). For example:

public class MyOptions
{
        private string _statusCodes;

        public IEnumerable<int> StatusCodesList { get; private set; }

        public string StatusCodes {    // CSV
            get { 
                return _statusCodes; 
            }
            set {
                StatusCodesList = value.Split(',').Select(s => int.Parse(s.Trim()));
                _statusCodes = value;
            }
        }    
}

@drago-draganov Thanks for the detailed explanation

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kamalsivalingam picture kamalsivalingam  路  3Comments

kamalsivalingam picture kamalsivalingam  路  6Comments

syndicatedshannon picture syndicatedshannon  路  7Comments

yegu-ms picture yegu-ms  路  7Comments

mmigala picture mmigala  路  4Comments