Alex Rivera | Logout

Is there a way to ensure a class library uses it's own app settings?

Asked 2011-05-19T01:56:14.287
11

I have a class library at the moment and it's going to need its own appsettings and it's likely going to need to change them and stuff.

The only problem is that the class is going to be called by a web application which has an appsettings file that also has identical keys to the class library app settings.

I would like to ensure that the class library uses it's own appsettings file and also that it doesn't make changes to the web application's appsettings.

Is this possible? It seems like any assembly can change the appsettings via ConfigurationManager.

EDIT - To give context, the class library accesses a data tier assembly (which I can't change) which uses a value in the appSettings to get the connection string. Only problem is that key is the same as the web app's connection string (which may or may not have a different value).

I don't want the class library to change the appSetting value for that key, and then have the web app start accessing a different database.

Edit
Report

1 Answer

1

Name your config file like below and place it in the same folder as your assembly: [AssemblyName].dll.config

Update: Anything that goes under can be used. You also use AppSettingsReader (http://msdn.microsoft.com/en-us/library/system.configuration.appsettingsreader.aspx) to create custom settings.

ex:

<configuration>
  <appSettings>
    <add key="YourCustomSetting" value="10240" />
  </appSettings>

  <system.diagnostics>
    ...
  </system.diagnostics>

  <connectionStrings>...
  <system.web>...
  etc, etc.
</configuration>
answered 2011-05-24T18:54:10.337

Your Answer