简体   繁体   中英

Should I use XML to store configuration settings in my C#.Net application?

My question relates to the performance implications of reading application configuration data from an XML file.

I am building an application that lists information from a database and needs to know how to display the lists, depending on the types of data returned.

This is difficult to explain, but basically I would like to have an XML config file that lists the types and describes how to display them. This will allow me to change the display methods without re-compiling the application.

My question is really around performance. Given that my application will need to use this data many times during each page load...

  • Should I be reading directly from the XML file and parse it each time I need it?
  • Or should I cache the XML object and parse it each time I need it?
  • Or should I parse the XML once, generate some sort of object and cache that object?

My guess is option 3, but I'm basically fishing for best practice around this.

Thanks.

There is already a convention for this, called the App.config file.

It is XML, and Visual Studio has tooling support for it.

My suggestion is: Don't reinvent the wheel, if you can help it.


Now, given that your format is too complex for that, you probably want to go with option 3, but load it lazily.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM