Mobile // Mobile Applications
Commentary
11/4/2008
00:00 AM
Commentary
Commentary
Commentary
Connect Directly
RSS
E-Mail
50%
50%

Config Reader Utility

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

Comment  | 
Print  | 
More Insights
Building A Mobile Business Mindset
Building A Mobile Business Mindset
Among 688 respondents, 46% have deployed mobile apps, with an additional 24% planning to in the next year. Soon all apps will look like mobile apps – and it's past time for those with no plans to get cracking.
Register for InformationWeek Newsletters
White Papers
Current Issue
InformationWeek Tech Digest September 24, 2014
Start improving branch office support by tapping public and private cloud resources to boost performance, increase worker productivity, and cut costs.
Video
Slideshows
Twitter Feed
InformationWeek Radio
Sponsored Live Streaming Video
Everything You've Been Told About Mobility Is Wrong
Attend this video symposium with Sean Wisdom, Global Director of Mobility Solutions, and learn about how you can harness powerful new products to mobilize your business potential.