Announcing: System.Configuration.Abstractions

What is it?

In most projects, you’re going to have some configuration. In .NET projects, it’ll probably start in your app.config or web.config file.

However, if you love TDD, you’ll likely have notice that all of the built in configuration classes are horribly un-testable. They all revolve around static references to System.Configuration.ConfigurationManager, and don’t really have any interfaces, so in every project, you end up wrapping them into something like “IAppSettingsWrapper”, in order to write tests.

After writing these wrappers what seems like hundreds of times, and being inspired by the excellent System.IO.Abstractions package, I’ve put together a standardised set of wrappers around these core framework classes.

Why Do I Need It?

* Want to mock/stub/whatever out your App/Web.config files?
* Want to assert that the values from configuration are *really* configuring your application?
* Want to add custom hooks around loading configuration values?
* Want stronger typing?

This is for you.

Where do I get it?

From source: https://github.com/davidwhitney/System.Configuration.Abstractions
By hand: https://www.nuget.org/packages/System.Configuration.Abstractions

NuGet:

        PM> Install-Package System.Configuration.Abstractions

Anything else?

I’ve also baked in a few strongly typed helpers to make your code a little less crufty (no more Int32.TryParse’ing your way to victory) along with a strong convention for “ConfigurationInterceptors” in case you’d like to hook in and add code around configuration reading.

Hopefully it’ll make your life just a little bit easier. More details in the readme on GitHub.

Leave a Reply