views:

141

answers:

3

I have some business objects which use:

Web.Configuration.WebConfigurationManager.AppSettings.Item("SomeSetting")

Now that I'm breaking those objects into their own library, it feels dirty to take a dependency on System.Web when nothing else in the library has anything to do with web.

What is the proper way to do this?

UPDATE: Found this example showing per-assembly config files. Is this a bad idea?

A: 

Why don't use Web.config? I saw in MSDN mention that it's properly analogue of app.config for web applications.

abatishchev
+1  A: 

Put it in web.config and call ConfigurationManager.AppSettings["KEY"]

No need for system.web in your libraries.

Henk
The advantage of using ConfigurationManager is that your separate libraries will pull the settings from the executing application when in use.
Aaron Fischer
+1  A: 

If you have a bunch of appSettings, I'm also a fan of using custom configuration sections by inheriting from ConfigurationSection, ConfigurationElement, etc from System.Configuration. This applies especially if these settings are tightly coupled to a specific area of your code.

This allows you to access the settings as strongly typed properties, and it also gives more control over which settings are required, allowed values for each setting (you can use enums), and you can also have collections.

How to: Create Custom Configuration Sections Using ConfigurationSection

Daniel Schaffer