Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IList<string> type always overrides values in config file #13

Open
sashazjukov opened this issue Mar 26, 2015 · 3 comments
Open

IList<string> type always overrides values in config file #13

sashazjukov opened this issue Mar 26, 2015 · 3 comments

Comments

@sashazjukov
Copy link

Using Interface IList in property declaration will force overriding List values in config files.
public IList ServerList { get; set; }

@RickStrahl
Copy link
Owner

Can you be a little more specific? What are you doing? Code sample?

@sashazjukov
Copy link
Author

in the example below use IList instead of List, and in the output config file you will not be able to change values of these keys:

< add key="ServerList1" value="DevServer" />
< add key="ServerList2" value="Maximus" />
< add key="ServerList3" value="Tempest" />

On every start the application will override values of ServerList in the output config file with values defined in constructor.

    public class CustomConfigFileConfiguration : Westwind.Utilities.Configuration.AppConfiguration
    {
         public string ApplicationName { get; set; }
         public IList <string> ServerList { get; set;  } //  <---- IList instead of List

        public CustomConfigFileConfiguration()
        {
            ApplicationName = "Configuration Tests";
            ServerList = new List<string>()
            {
                "DevServer",
                "Maximus",
                "Tempest"
            };
        }
    }

@dragnilar
Copy link

2 years later...

I was having this problem too. It was driving me nuts, because Rick was doing it without any problems in the unit tests for CustomConfigFileConfiguration. I took a look around and discovered that he wasn't using a custom configuration file in his test. I tried using the default file in mine, and lo and behold I was able to retrieve my list after writing and restarting or making a new config object. I then went back to his unit test and tried using a custom file, and his test would fail.

I dug a little deeper and found out that it's because the library doesn't do the same thing with Lists that it does when you don't tell it to use a custom file. I had to make a change to the source to get Lists to work with custom config files. I'm not sure if it's worth sharing though, since it feels like a hack. For what it's worth, the same "problem" exists in the full WestWind.Utilities' configuration class as well. But of course I could have just been doing it wrong this entire time, but I couldn't find any examples that would say otherwise and unfortunately the documentation website for this library seems to be down at the moment (http://west-wind.com/westwind.applicationconfiguration/docs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants