Feb 26

I ran into the rock and hard place .NET configuration situation again recently. The way we use the web.config or app.config via System.Configuration hasn’t really changed since .NET 2.0. Like most .NET developers I want the flexibility of appSettings with the benefits of using a strongly typed class, which you traditionally get from inheriting System.Configuration.ConfigurationSection .

Basically I want all of the advantages of appSettings and ConfigurationSection without any ceremony, friction, monkey casting or magic strings. Naturally I want to use Json in my config files not Xml, but I still want to store my config with the rest of my config in my web.config/app.config files.

At the risk of reinventing the wheel I know that there are dozens of NuGet packages that solve these issues – but I have one more requirement though I need a solution that works with web.config, app.config and Azure Service Configuration .cscfg files.

Currently I’m working on a Web Api project that is deployed to Azure. Whilst developing for speed I don’t use the Azure emulator, so I need my project to look for configuration in my web.config not the .cscfg file. Again for the same reasons my integration test project needs to look for configuration in my app.config. When running the same projects in the Azure emulator or when deployed to Azure I need them to look for configuration in Azure’s .cscfg file, giving me all of the benefits Azure service configuration offers.

This is my motivation for creating DalSoft.Configuration, yes I could of extended one of the many config projects out there to work with .cscfg files, but I wanted the simplest .NET configuration that could possibly work.

How easy is it to use DalSoft.Configuration?

Turns out it is extremely trivial to use!

Create a class that inherits from DalSoft.Configuration.JsonConfig:

Add the following appSettings to your app or web.config:

Now you can access your configuration by simply calling GetSettings() on the class you just created for example:

MyAppConfig.GetSettings();

MyAppConfig.GetSettings().Website; will return “http://dalsoft.co.uk/”

Where can I find DalSoft.Configuration?

You guessed right?

GitHub
More examples, documentation and source.
https://github.com/DalSoft/DalSoft.Configuration

NuGet

PM> Install-Package DalSoft.Configuration

Leave a Reply

preload preload preload