|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
app.config for class library?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 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. -- Show quoteGregory A. Beamer MVP; MCP: +I, SE, SD, DBA *************************** Think Outside the Box! *************************** "mfc_mobile@newsgroup.nospam" wrote: > 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 > > > mfc_mobile@newsgroup.nospam wrote:
> Hi, No. Not in the sense that Microsoft uses the term.> > 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#. 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 -- http://www.grimes.demon.co.uk/workshops/fusionWS.htm http://www.grimes.demon.co.uk/workshops/securityWS.htm |
|||||||||||||||||||||||