473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

config files - how to avoid clutter?

Many of an app's classes could read the config file. The config file could
contain many elements, and it will be difficult to know which config file
entry belongs to which class. I could adopt a naming scheme for the
elements. But am I limited to using the <appSettings> element for my
settings? It would be good to have elements such as <myClass1Stuff> so that
it's easy to tell which settings go with each class. But whether I put
<myClass1Stuff> in the <configuration> element or the <appSettings> element,
I receive configuration errors. Does anyone have good ideas/suggestions for
keeping the configuration entries manageable? Thanks!
Jul 19 '05 #1
1 1607
Marty,
Go ahead and create a section new sections in the app.config file.

There is a predefined configSections section in the app.config that you use
to define new sections.

Something like:

<configuration>

<configSections>
<section name="myClass1Stuff"
type="System.Configuration.DictionarySectionHandle r, System" />
<sectionGroup name="environments">
<section name="production"
type="System.Configuration.SingleTagSectionHandler , System" />
<section name="development"
type="System.Configuration.SingleTagSectionHandler , System" />
</sectionGroup>
</configSections>

<appSettings>
<add key="key1" value="value1" />
<add key="environment" value="production" />
</appSettings>

<myClass1Stuff>
<add key="key1" value="value1" />
</myClass1Stuff>

<environments>
<production value1="xyz" value2="abc" value3="edf" value4="ghi" />
<development value1="xyz" value2="abc" value3="edf" value4="ghi" />
</environments>

</configuration>

If you inherit from DictionarySectionHandler you can easily change the key
or value in your section. I've derived from DictionarySectionHandler to
change key/value to plugin/type in a few of my projects.

I use the above environments section to define each of my environments,
Production, QA, Test, Development. Where each environment points to the
correct database servers, web servers, message queues, printers any 'per
environment' settings. The appSettings/environment setting is used to
identify the current environment in use.

You then need to use System.Configuration.ConfigurationSettings.GetConf ig to
get your section, which returns an object based on the type of section
handler defined for that section (usually HashTable, but can be other object
types.

See the following on how to create new sections via the configSections
section.

http://msdn.microsoft.com/library/de...onhandlers.asp

and:
http://msdn.microsoft.com/library/de...ionsschema.asp

Also read about the System.Configuration.ConfigurationSettings class and
other classes in the System.Configuration namespace.

Hope this helps
Jay

"Marty McDonald" <mc******@wsdot.wa.gov> wrote in message
news:OU**************@TK2MSFTNGP10.phx.gbl...
Many of an app's classes could read the config file. The config file could contain many elements, and it will be difficult to know which config file
entry belongs to which class. I could adopt a naming scheme for the
elements. But am I limited to using the <appSettings> element for my
settings? It would be good to have elements such as <myClass1Stuff> so that it's easy to tell which settings go with each class. But whether I put
<myClass1Stuff> in the <configuration> element or the <appSettings> element, I receive configuration errors. Does anyone have good ideas/suggestions for keeping the configuration entries manageable? Thanks!

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Frank Oquendo | last post by:
ConfigurationSettings.AppSettings allows me to read from my config but how do I write to my config file? -- There are 10 kinds of people. Those who understand binary and those who don't. ...
5
by: BPearson | last post by:
Hello I would like to have several sites share a single web.config file. To accomplish this, I would point the root of these sites to the same folder. Is there any reason why I might not want to...
7
by: Bob | last post by:
It's great that VS.NET makes it so effortless to add a web reference to a web service. The problem is, I haven't figured out a way to configure the URLs (or simply switch the references to another...
9
by: Benny Ng | last post by:
Hi,all, How to let the sub-directory to avoid the authentication control from Root's webconfig? I heard that we can add a new web.config to the sub-directory. And then we can slove the problem....
1
by: Marty McDonald | last post by:
Many of an app's classes could read the config file. The config file could contain many elements, and it will be difficult to know which config file entry belongs to which class. I could adopt a...
0
by: marfi95 | last post by:
I have 2 questions. First a little background. I have an app that is used by my entire team to parse files and some other stuff that we normally do during the day. This app is driven very...
2
by: OO | last post by:
Hi all, OK loads of posts on here about developers trying to use an app.config for a dll class library. Of course I would normally say the config file is down to the app domain of the...
0
by: Willy Van den Driessche | last post by:
I put my datasets inside a DLL (I have moved them out of app_code to avoid the clutter). These are typed datasets for which the code is generated by dotnet. To be able to generate them I have...
3
by: =?Utf-8?B?RHVrZSAoQU4yNDcp?= | last post by:
I've added a web deployment project and want to use the config section replacement but I'm obviously not understanding something. I have set up an alternate appSettings file,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.