Tech Off Thread

6 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Configuration Files

Back to Forum: Tech Off
  • User profile image
    Rafa®

    .Net stores configuration in XML files, named with the .config extension, where in the Web case, the file is called Web.Config, and in applications case, the file is the [name of the assembly].config, so, my question is... Can I assign a configuration file for specific Assemblies?
     
    Assuming my project use 2 distinct Assemblies, the main one, wich is an Windows Forms Executable, and a DLL for the Bussiness Layer...
     
    BL.dll
    MyApp.exe
     
    If I want two config files, could I use:
     
    BL.config
    MyApp.config
     
    So, when BL.dll read something from Configuration file, it gets from it's own .config, and the same for MyApp.exe...
     
    I don't even know if it's useful for something, but I was wondering...
    Because, I was developing with unit testing, and I was searching a way to the testing assembly gets the ConnectionString from the Configuration file (it's still unsolved)... Then it comes up in my mind...
     
    Thanks..

  • User profile image
    aza

    Rafa® wrote:
    I don't even know if it's useful for something, but I was wondering...
    Because, I was developing with unit testing, and I was searching a way to the testing assembly gets the ConnectionString from the Configuration file (it's still unsolved)... Then it comes up in my mind...
    If you are using NUnit you can specify the configuration file for the assembly being tested. In addition if you are also using Nant it's all wrapped up nicely in an XML file for you Smiley.

    Aaron

  • User profile image
    AndyJ

    Since you mention unit testing, if you're using NUnit, they do use an assembly by assembly config file approach. Any dll that calls the standard ConfigurationSettings methods will be directed to a config file with the name of the tested assembly. In other words if I'm testing MyDLL.DLL the config file will be MyDLL.DLL.Config rather than MyAPP.EXE.Config.

    However, if you want to know how to load a config file for independant assemblies, there are methods. One way is to load your DLL into a seperate AppDomain. Each appDomain can specify it's own Config file. Another, perhaps easier way, is to write your own version of ConfigurationSettings that opens up a DLL specific config file as a regular XML file and parses out the data....

    -Andy
    www.geekswithblogs.org/ajohns

  • User profile image
    Steve411

    "

    If I want two config files, could I use:
     
    BL.config
    MyApp.config"

    well yes, you could, but in the BL.dll file you would have to specify the .config file, likewise for the MyApp.exe...

  • User profile image
    Steve411

    Forgot something..
    Why .config? Why not store the config data in an encrypted XML file?... Works better for security measures.

    this is how i do it..
     
    BL.xml.config
    MyApp.xml.config

  • User profile image
    Steve411

    Encryption is the key for security reasons

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.