November 5, 2008
@ 07:30 PM
Reshef Mann, one of the members of our devdiv released a nifty little utility for reading configuration files into easy to work-with type-safe interface.
Instead of trying to explain it - Here is the example from his Getting Started :

When you have .config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 
<appSettings>
   
<add key="MailNotificationSettings.SmtpServerAddress" value="http://localhost"/>
   
<add key="MailNotificationSettings.Username" value="user123"/>
   
<add key="MailNotificationSettings.Password" value="passwd123"/>
 
</appSettings>
</configuration>

Define the following interface:

public interface IMailNotificationSettings
{
   
Uri SmtpServerAddress { get; }
   
string Username { get; }
   
string Password { get; }
}

And from your program use this code:

public static void Main()
{
       
ConfigurationReader configReader = new ConfigurationReader().SetupConfigOf<IMailNotificationSettings>();
       
IMailNotificationSettings mailNotificationSettings = configReader.ConfigBrowser.Get<IMailNotificationSettings>();
       
       
var mailNotificationService = new MailNotificationService(mailNotificationSettings);
       
       
//
       
//      Do the work..
       
//
}


The project is open sourced under the Apache 2.0 license- so feel free to use it


 
Friday, November 07, 2008 11:37:53 AM (GMT Standard Time, UTC+00:00)
Thanks! Useful utility for me.
Friday, November 07, 2008 12:52:56 PM (GMT Standard Time, UTC+00:00)
I'll pass that to Reshef :)
Monday, November 10, 2008 4:37:25 PM (GMT Standard Time, UTC+00:00)
Great utility thanks. This might be a great thing to combine with some of the new features coming out in c# 4.0, for instance, take Mark's example with xml(http://mark.michaelis.net/Blog/DynamicallyTypedObjectsWithC40.aspx) and apply that to the configuration library, now you are not necessarily forced into having to create an interface for your configuration.

True, you would lose the type-safety, but you get the brevity of simple and easy configuration. I guess you have to decide what is the better fit for your project.
Bryan Smith
Comments are closed.