<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Config files for DLLs</title>
	<atom:link href="http://prettycode.org/2009/11/13/config-files-for-dlls/feed/" rel="self" type="application/rss+xml" />
	<link>http://prettycode.org/2009/11/13/config-files-for-dlls/</link>
	<description>foreach(bill) paywith(skill);</description>
	<lastBuildDate>Fri, 05 Mar 2010 01:42:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Denisha Sangasy</title>
		<link>http://prettycode.org/2009/11/13/config-files-for-dlls/comment-page-1/#comment-2099</link>
		<dc:creator>Denisha Sangasy</dc:creator>
		<pubDate>Fri, 08 Jan 2010 15:17:34 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=383#comment-2099</guid>
		<description>Interessanter Beitrag, vielen Dank.</description>
		<content:encoded><![CDATA[<p>Interessanter Beitrag, vielen Dank.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc Schubert</title>
		<link>http://prettycode.org/2009/11/13/config-files-for-dlls/comment-page-1/#comment-1508</link>
		<dc:creator>Marc Schubert</dc:creator>
		<pubDate>Thu, 26 Nov 2009 21:58:20 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=383#comment-1508</guid>
		<description>Hi,

each assembly (wheter is an DLL or an EXE) has the opportunity to store its configuratios in an app.config-File.
Makes it sense ? It&#039;s appropriate to your custom scneario, so i can&#039;t give an generic answer.

An easy way to get the configs of your Assembly is by using System.Reflection.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Reflection;

namespace Marc.MyLibrary
{
    public class MySampleClass
    {
        public static string DoSomething()
        {
            // Preferences: Store an App-Config beside your Assembly (DLL or EXE)
            // named as a regular app.config
            // example: 
	    // Marc.MyLibrary.dll
	    // Marc.MyLibrary.dll.config

	    // 1) Get the Location of your Assembly
	   
            string path = typeof(MySampleClass).Assembly.Location;
            
	    // 2) Use the path to get an Configuration-Object via ConfigurationManager
	    //    (Info: Please set a reference to System.Configuration)

	    Configuration config = ConfigurationManager.OpenExeConfiguration(path);

	    // 3) Access via Indexer on your defined key
            string myValue = config.AppSettings.Settings[&quot;MyKey&quot;].Value;

            return myValue;
        }

    }
}





  
    
  


Regards,

Marc</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>each assembly (wheter is an DLL or an EXE) has the opportunity to store its configuratios in an app.config-File.<br />
Makes it sense ? It&#8217;s appropriate to your custom scneario, so i can&#8217;t give an generic answer.</p>
<p>An easy way to get the configs of your Assembly is by using System.Reflection.</p>
<p>using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Configuration;<br />
using System.Reflection;</p>
<p>namespace Marc.MyLibrary<br />
{<br />
    public class MySampleClass<br />
    {<br />
        public static string DoSomething()<br />
        {<br />
            // Preferences: Store an App-Config beside your Assembly (DLL or EXE)<br />
            // named as a regular app.config<br />
            // example:<br />
	    // Marc.MyLibrary.dll<br />
	    // Marc.MyLibrary.dll.config</p>
<p>	    // 1) Get the Location of your Assembly</p>
<p>            string path = typeof(MySampleClass).Assembly.Location;</p>
<p>	    // 2) Use the path to get an Configuration-Object via ConfigurationManager<br />
	    //    (Info: Please set a reference to System.Configuration)</p>
<p>	    Configuration config = ConfigurationManager.OpenExeConfiguration(path);</p>
<p>	    // 3) Access via Indexer on your defined key<br />
            string myValue = config.AppSettings.Settings["MyKey"].Value;</p>
<p>            return myValue;<br />
        }</p>
<p>    }<br />
}</p>
<p>Regards,</p>
<p>Marc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://prettycode.org/2009/11/13/config-files-for-dlls/comment-page-1/#comment-1424</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Thu, 19 Nov 2009 00:46:03 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=383#comment-1424</guid>
		<description>@Chris W: I like your idea. To be more useful, there definitely needs to be a way to load config files if an config&#039;d assembly resides in the GAC. A global config location sounds great. Aside from checking the directory of the assembly that referencing the assembly with the config file, I don&#039;t know what else one could do. Thanks for the suggestion!</description>
		<content:encoded><![CDATA[<p>@Chris W: I like your idea. To be more useful, there definitely needs to be a way to load config files if an config&#8217;d assembly resides in the GAC. A global config location sounds great. Aside from checking the directory of the assembly that referencing the assembly with the config file, I don&#8217;t know what else one could do. Thanks for the suggestion!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://prettycode.org/2009/11/13/config-files-for-dlls/comment-page-1/#comment-1423</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Thu, 19 Nov 2009 00:25:54 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=383#comment-1423</guid>
		<description>@PhlyingPenguin: Nice name :). Anywho, centralized configurations are generally a good idea&#8212;just like variables, you don&#039;t want five definitions of the same setting being five identical config files. That&#039;s a recipe for disaster, surely. One option for storing settings, as you say, is an configuration file per application. .NET has built-in functionality for that. Another more flexible option might be putting settings in a database. 

There are times when it&#039;s better to be more modular, however. A per-assembly config file definitely isn&#039;t the best solution for all configuration needs, but it&#039;s one solution to one particular problem.

I&#039;ll give you an example: at my last employer, we had four servers downloading images, all using the same DLL to help accomplish this. One of the settings in the DLL was where to cache the images. In this scenario, the local paths where the images were cached actually needed to be different on each server as a result of the servers&#039; hardware (physical drive sizes). 

The application using this DLL already had a largly bloated configuration file for itself, so separating out the concerns of the particular DLL into its own config file made changing settings related to image caching easier.

The point of libraries, like you say, is to be modular and recyclable, and that&#039;s exactly what &lt;i&gt;decoupling&lt;/i&gt; the DLL settings from the application&#039;s settings does. Is it always the best idea? No. Sometimes? Sure.</description>
		<content:encoded><![CDATA[<p>@PhlyingPenguin: Nice name <img src='http://prettycode.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Anywho, centralized configurations are generally a good idea&mdash;just like variables, you don&#8217;t want five definitions of the same setting being five identical config files. That&#8217;s a recipe for disaster, surely. One option for storing settings, as you say, is an configuration file per application. .NET has built-in functionality for that. Another more flexible option might be putting settings in a database. </p>
<p>There are times when it&#8217;s better to be more modular, however. A per-assembly config file definitely isn&#8217;t the best solution for all configuration needs, but it&#8217;s one solution to one particular problem.</p>
<p>I&#8217;ll give you an example: at my last employer, we had four servers downloading images, all using the same DLL to help accomplish this. One of the settings in the DLL was where to cache the images. In this scenario, the local paths where the images were cached actually needed to be different on each server as a result of the servers&#8217; hardware (physical drive sizes). </p>
<p>The application using this DLL already had a largly bloated configuration file for itself, so separating out the concerns of the particular DLL into its own config file made changing settings related to image caching easier.</p>
<p>The point of libraries, like you say, is to be modular and recyclable, and that&#8217;s exactly what <i>decoupling</i> the DLL settings from the application&#8217;s settings does. Is it always the best idea? No. Sometimes? Sure.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Winberry</title>
		<link>http://prettycode.org/2009/11/13/config-files-for-dlls/comment-page-1/#comment-1422</link>
		<dc:creator>Chris Winberry</dc:creator>
		<pubDate>Wed, 18 Nov 2009 23:36:02 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=383#comment-1422</guid>
		<description>@Chris: regarding assemblies in the GAC: I created a very similar solution to yours that is used by large group of developers across multiple libraries and apps that must live on the same system. The way I handled assemblies in the GAC was to create a &quot;GlobalConfigDir&quot; key in the machine config that points to a shared location where an assembly&#039;s config may be found. The config loader then scanned for the config file in the following order (assuming Foo.dll v1.0.0.0):

- [Current assembly location]/Foo.1.0.0.dll.config
- [Current assembly location]/Foo.dll.config
- [GlobalConfigDir]/Foo.1.0.0.dll.config
- [GlobalConfigDir]/Foo.dll.config
 
Care must be taken however, because in larger systems, there&#039;s enough rope to hang one&#039;s self (winding up with too many configs to track and update).</description>
		<content:encoded><![CDATA[<p>@Chris: regarding assemblies in the GAC: I created a very similar solution to yours that is used by large group of developers across multiple libraries and apps that must live on the same system. The way I handled assemblies in the GAC was to create a &#8220;GlobalConfigDir&#8221; key in the machine config that points to a shared location where an assembly&#8217;s config may be found. The config loader then scanned for the config file in the following order (assuming Foo.dll v1.0.0.0):</p>
<p>- [Current assembly location]/Foo.1.0.0.dll.config<br />
- [Current assembly location]/Foo.dll.config<br />
- [GlobalConfigDir]/Foo.1.0.0.dll.config<br />
- [GlobalConfigDir]/Foo.dll.config</p>
<p>Care must be taken however, because in larger systems, there&#8217;s enough rope to hang one&#8217;s self (winding up with too many configs to track and update).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: phlyingpenguin</title>
		<link>http://prettycode.org/2009/11/13/config-files-for-dlls/comment-page-1/#comment-1421</link>
		<dc:creator>phlyingpenguin</dc:creator>
		<pubDate>Wed, 18 Nov 2009 23:12:05 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=383#comment-1421</guid>
		<description>This sounds like a very MS.NET centric view of the world. If you need one configuration to be passed into a library then it sounds to me like you need central config files instead of per application or (GAH!) per library configs. Think UNIX. Even if a separate library is the party parsing the config file and the program is only optionally passing in options, this allows much more control and makes much more sense in terms of reusing the library. Libraries should be reused and be able to be recycled in ANY configuration situation, with or without a config file.</description>
		<content:encoded><![CDATA[<p>This sounds like a very MS.NET centric view of the world. If you need one configuration to be passed into a library then it sounds to me like you need central config files instead of per application or (GAH!) per library configs. Think UNIX. Even if a separate library is the party parsing the config file and the program is only optionally passing in options, this allows much more control and makes much more sense in terms of reusing the library. Libraries should be reused and be able to be recycled in ANY configuration situation, with or without a config file.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://prettycode.org/2009/11/13/config-files-for-dlls/comment-page-1/#comment-1387</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Tue, 17 Nov 2009 05:36:38 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=383#comment-1387</guid>
		<description>@Yngve: in that case, you&#039;re just out of luck. Or, do you think having the .config file for the DLL in  the same directory as the .exe or application referencing the DLL would be a good idea? Have any suggestions?</description>
		<content:encoded><![CDATA[<p>@Yngve: in that case, you&#8217;re just out of luck. Or, do you think having the .config file for the DLL in  the same directory as the .exe or application referencing the DLL would be a good idea? Have any suggestions?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yngve</title>
		<link>http://prettycode.org/2009/11/13/config-files-for-dlls/comment-page-1/#comment-1367</link>
		<dc:creator>Yngve</dc:creator>
		<pubDate>Mon, 16 Nov 2009 08:31:55 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=383#comment-1367</guid>
		<description>So how would this work if you have the assembly added to GAC?</description>
		<content:encoded><![CDATA[<p>So how would this work if you have the assembly added to GAC?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://prettycode.org/2009/11/13/config-files-for-dlls/comment-page-1/#comment-1354</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Sun, 15 Nov 2009 21:43:00 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=383#comment-1354</guid>
		<description>@JMP: I&#039;ve worked on many projects where a DLL was used across multiple, even tens, of applications. It&#039;s a lot easier to copy a DLL along with its .config file to be used with an application than to change every application&#039;s .config that uses that DLL. 

Plus, we have separate assemblies to keep separations of concerns with code. You create a DLL instead of adding the code to an application so that it can be plugged into an application. Just like keeping that DLL code separate from an application&#039;s codebase is a good idea, so is keeping settings that only apply to that DLL, don&#039;t you think?</description>
		<content:encoded><![CDATA[<p>@JMP: I&#8217;ve worked on many projects where a DLL was used across multiple, even tens, of applications. It&#8217;s a lot easier to copy a DLL along with its .config file to be used with an application than to change every application&#8217;s .config that uses that DLL. </p>
<p>Plus, we have separate assemblies to keep separations of concerns with code. You create a DLL instead of adding the code to an application so that it can be plugged into an application. Just like keeping that DLL code separate from an application&#8217;s codebase is a good idea, so is keeping settings that only apply to that DLL, don&#8217;t you think?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CRG</title>
		<link>http://prettycode.org/2009/11/13/config-files-for-dlls/comment-page-1/#comment-1350</link>
		<dc:creator>CRG</dc:creator>
		<pubDate>Sun, 15 Nov 2009 16:53:08 +0000</pubDate>
		<guid isPermaLink="false">http://prettycode.org/?p=383#comment-1350</guid>
		<description>I&#039;m not sure how it is in VC#, but in VB, you could use the settings designer to create a settings file for a dll.

JMP, one usage scenario, plug-ins.</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure how it is in VC#, but in VB, you could use the settings designer to create a settings file for a dll.</p>
<p>JMP, one usage scenario, plug-ins.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
