﻿<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://developers.de/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Extending .NET 2.0 Configuration</title><link />http://developers.de/blogs/damir_dobric/archive/2007/02/07/Extending-.NET-2.0-Configuration.aspx<description>.NET 2.0 offers very powerful configuration mechanism, which allows you to build you custom configuration sections, elements etc. Unfortunately, many details are very poor documented. In this post I will shortly show some interesting details. For example</description><dc:language>en</dc:language><generator>CommunityServer 2008 SP1 (Build: 30619.63)</generator><item><title>re: Extending .NET 2.0 Configuration</title><link />http://developers.de/blogs/damir_dobric/archive/2007/02/07/Extending-.NET-2.0-Configuration.aspx#1787<pubdate>Tue, 05 Feb 2008 07:17:39 GMT</pubdate><guid ispermalink="false">7e491611-45ad-4dae-a68f-c4cb64439510:1787</guid><dc:creator>Damir Dobric</dc:creator><description>&lt;p&gt;This is right Todd. You do not have to. The idea of this example was to show how to do that behind the scene. For example, my requirement was to load the configuration from database or to collect information from several web services, put them together and create the dynamically configuration node.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://developers.de/aggbug.aspx?PostID=1787" width="1" height="1"&gt;</description></item><item><title>re: Extending .NET 2.0 Configuration</title><link />http://developers.de/blogs/damir_dobric/archive/2007/02/07/Extending-.NET-2.0-Configuration.aspx#1784<pubdate>Mon, 04 Feb 2008 20:05:11 GMT</pubdate><guid ispermalink="false">7e491611-45ad-4dae-a68f-c4cb64439510:1784</guid><dc:creator>Todd Taylor</dc:creator><description>&lt;p&gt;I found-out that you don't need to define the &amp;quot;File&amp;quot; property if you want to use a linked configuration file (as shown in the sample code download). &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Instead, add the attribute &amp;quot;configSource&amp;quot; which is part of the .NET Framework: &amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;lt;MyCustomSection configSource=&amp;quot;Configuration\MyConfig.config&amp;quot; /&amp;gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://developers.de/aggbug.aspx?PostID=1784" width="1" height="1"&gt;</description></item><item><title>re: Extending .NET 2.0 Configuration</title><link />http://developers.de/blogs/damir_dobric/archive/2007/02/07/Extending-.NET-2.0-Configuration.aspx#1781<pubdate>Thu, 31 Jan 2008 23:19:46 GMT</pubdate><guid ispermalink="false">7e491611-45ad-4dae-a68f-c4cb64439510:1781</guid><dc:creator>Todd Taylor</dc:creator><description>&lt;p&gt;Thank you, Damir, for posting this article and code sample. &amp;nbsp; I was totally stuck with trying to create the appropriate classes for a rather complicated configuration file. &amp;nbsp; Most of the code samples I found online were too basic to help me resolve the issues I was having. &amp;nbsp;Thanks to your code sample, I was able to get my code working :o)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://developers.de/aggbug.aspx?PostID=1781" width="1" height="1"&gt;</description></item><item><title>re: Extending .NET 2.0 Configuration</title><link />http://developers.de/blogs/damir_dobric/archive/2007/02/07/Extending-.NET-2.0-Configuration.aspx#1583<pubdate>Mon, 01 Oct 2007 08:44:38 GMT</pubdate><guid ispermalink="false">7e491611-45ad-4dae-a68f-c4cb64439510:1583</guid><dc:creator>Damir Dobric</dc:creator><description>&lt;p&gt;Here is an example which shows how to read bindings by using of section path:&lt;/p&gt;
&lt;p&gt;configuration.GetSection(&amp;quot;system.serviceModel/bindings&amp;quot;)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://developers.de/aggbug.aspx?PostID=1583" width="1" height="1"&gt;</description></item><item><title>re: Extending .NET 2.0 Configuration</title><link />http://developers.de/blogs/damir_dobric/archive/2007/02/07/Extending-.NET-2.0-Configuration.aspx#1534<pubdate>Mon, 03 Sep 2007 15:28:28 GMT</pubdate><guid ispermalink="false">7e491611-45ad-4dae-a68f-c4cb64439510:1534</guid><dc:creator>Ed</dc:creator><description>&lt;p&gt;Wow, you answered fast :) thanks :)&lt;/p&gt;
&lt;p&gt;Yep, it helped :) I had to separate the 2 collections in separate Section properties... then I add manually a property (not ConfigurationProperty) that merges both, so my Logger class still works the same.&lt;/p&gt;
&lt;p&gt;Just a little observation, at first it didn't load my values, searching in other sites I saw I still needed another thing to use them, guess you have that also somewhere your program but forgot to write it here:&lt;/p&gt;
&lt;p&gt;_settings = (MySection) ConfigurationManager.GetSection(&amp;quot;MySection&amp;quot;);&lt;/p&gt;
&lt;p&gt;Bye :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://developers.de/aggbug.aspx?PostID=1534" width="1" height="1"&gt;</description></item><item><title>re: Extending .NET 2.0 Configuration</title><link />http://developers.de/blogs/damir_dobric/archive/2007/02/07/Extending-.NET-2.0-Configuration.aspx#1531<pubdate>Mon, 03 Sep 2007 12:46:49 GMT</pubdate><guid ispermalink="false">7e491611-45ad-4dae-a68f-c4cb64439510:1531</guid><dc:creator>Damir Dobric</dc:creator><description>&lt;p&gt;Hi Ed, you class is the usual one, but a little bit more tricky. The way you want to use class derivation reflected to the configuration is not well object oriented design. &lt;/p&gt;
&lt;p&gt;In general, there are two ways to do that:&lt;/p&gt;
&lt;p&gt;&amp;lt;LogSettings&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;lt;Destinations&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;lt;Destination provider=”file” providerSettings=”…”/&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;lt;Destination provider=”db” providerSettings=”here connection string etc”/&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;lt;Destination provider=”whatever” providerSettings=”…”/&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;LogSettings&amp;gt;&lt;/p&gt;
&lt;p&gt;or &lt;/p&gt;
&lt;p&gt;LogSettings&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Destinations&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;FileDestination&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;DbDestination&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;WhatEverDestination&lt;/p&gt;
&lt;p&gt;If you use the first one, it is not the typed one. In this case you would work provider specific (similar like ADO.NET). In this case the Destinations element would be a ConfigurationElementCollection. Destination element would be usual ConfigElement.&lt;/p&gt;
&lt;p&gt;In the second case the Destinations element is a ConfigElement and all other DestinationXXX should be members of that element.&lt;/p&gt;
&lt;p&gt;In boot cases, LogSettings could be a section.&lt;/p&gt;
&lt;p&gt;Hope this help. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://developers.de/aggbug.aspx?PostID=1531" width="1" height="1"&gt;</description></item><item><title>re: Extending .NET 2.0 Configuration</title><link />http://developers.de/blogs/damir_dobric/archive/2007/02/07/Extending-.NET-2.0-Configuration.aspx#1530<pubdate>Mon, 03 Sep 2007 11:50:06 GMT</pubdate><guid ispermalink="false">7e491611-45ad-4dae-a68f-c4cb64439510:1530</guid><dc:creator>Ed</dc:creator><description>&lt;p&gt;Hi, that's interesting for normal configuration sections, but mine isn't normal :D, I have an abstract class called Destination, and 2 derived classes called FileDestination and DbDestination so I can have a Destinations collection and call the abstract WriteEntry method for all Destinations.&lt;/p&gt;
&lt;p&gt;Well, I'd like to use a config section similar to:&lt;/p&gt;
&lt;p&gt;&amp;lt;LogSettings&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;lt;Destinations&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;lt;FileDestination&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;Filename&amp;gt;filename&amp;lt;/Filename&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;Path&amp;gt;path&amp;lt;/Path&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;Enabled&amp;gt;true&amp;lt;/Enabled&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;lt;/FileDestination&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;lt;DbDestination&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;ConnectionString&amp;gt;connection string&amp;lt;/ConnectionString&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;TableName&amp;gt;table&amp;lt;/TableName&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;Enabled&amp;gt;true&amp;lt;/Enabled&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;lt;/DbDestination&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;lt;/Destinations&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;/LogSettings&amp;gt;&lt;/p&gt;
&lt;p&gt;Is it possible? how??&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://developers.de/aggbug.aspx?PostID=1530" width="1" height="1"&gt;</description></item><item><title>Reading of WCF configuration</title><link />http://developers.de/blogs/damir_dobric/archive/2007/02/07/Extending-.NET-2.0-Configuration.aspx#1191<pubdate>Wed, 07 Feb 2007 22:32:07 GMT</pubdate><guid ispermalink="false">7e491611-45ad-4dae-a68f-c4cb64439510:1191</guid><dc:creator>Damir Dobric Posts</dc:creator><description>&lt;p&gt;Sometimes it is required to read the WCF specific information contained in the application's configuration&lt;/p&gt;
&lt;img src="http://developers.de/aggbug.aspx?PostID=1191" width="1" height="1"&gt;</description></item></channel></rss>