Do you make a strongly-typed wrapper for app.config?

Loading last updated info...

If your application accesses properties in app.config, you should provide a strongly typed wrapper for the app.config file. The following code shows you how to build a simple wrapper for app.config in an AssemblyConfiguration class:

using System;
using System.Configuration;
namespace SSW.Northwind.WindowsUI
{
public sealed class AssemblyConfiguration
{
// Prevent the class from being constructed
private AssemblyConfiguration() { }
public static string ConnectionString
{
get
{
return
ConfigurationSettings.AppSettings["ConnectionString"].
ToString();
}
}
}
}

Unfortunately, the Configuration Block does not automatically provide this wrapper.

Authors

Need help?

SSW Consulting has over 30 years of experience developing awesome software solutions.

We open source.Loving SSW Rules? Star us on GitHub. Star