app.config for class library?

G

Guest

Hi,

Is it possible to have a app.config for a class library as well as a
app.config for an application calling the class library? I'm using C#.

thanks
 
G

Guest

Yes, but not in the traditional manner. Let me explain.

App.config files are used to configure an app domain. To put this in simpler
terms, this means that the app that controls all of the libraries will be the
config in effect. If you attempt to pull configuration from a library under
control of an app, it will read that config file and not the one for your
library.

To get around this, you have a couple of options.

1. Dump a "config" (XML?) file in the application directory that the class
library can read. This is a bit kludgy, as the class library is breaking from
normal convention.

2. Move to SOA. This means wrapping the class library in a service (windows
or web (note that "web service", to me, is either ASMX or Remoting)). The
service then, technically, has the class library's "config". This option fits
well with Microsoft's vision.

3. Create a "config" service that the class library can contact. This is not
pure SOA and thus not as recommended, but it is certainly better than option
1.

Ultimately, if you want two configs, you should have two applications. The
SOA concept in .NET 2.0 (which can be used in 1.x) is a good option, as it
will continue to gain MS support (as well as industry support). The downside
is you need to change you thinking towards messaging to make this option
really viable.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
R

Richard Grimes [MVP]

Hi,

Is it possible to have a app.config for a class library as well as a
app.config for an application calling the class library? I'm using C#.

No. Not in the sense that Microsoft uses the term.

The issue is that when an application domain starts it will load the
application's configuration file and it will cache the values. Framework
classes use data in the config file and this is th only way that this
data gets into the application.

If you write you own version of 'config file' then the data is only
accessible to classes in your library. There is nothing wrong with this
approach. I do it myself, usually by creating a config class and
serializing it with XmlSerializer (xsd.exe is a great tool to help you
here). However, you cannot add configuration for *any* of the framework
classes because they get their values from the application config file
(or machine.config).

http://www.grimes.demon.co.uk/dotnet/configFAQ.htm

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top