Config Reader Utility

Reshef Mann, one of the members of <a href="http://www.xsights.com/">our</a> devdiv <a href="http://code.google.com/p/configreader/">released </a>a nifty little utility for reading configuration files into easy to work-with type-safe interface.<br />Instead of trying to explain it - Here is the example from his <a href="http://code.google.com/p/configreader/wiki/GettingStarted">Getting Started</a> :<br /> <blockquote>

InformationWeek Staff, Contributor

November 4, 2008

2 Min Read
InformationWeek logo in a gray background | InformationWeek

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

Never Miss a Beat: Get a snapshot of the issues affecting the IT industry straight to your inbox.

You May Also Like


More Insights