Quantcast
Channel: Reading settings from app.config or web.config in .NET - Stack Overflow
Viewing all articles
Browse latest Browse all 29

Answer by Tony O'Hagan for Reading settings from app.config or web.config in .NET

$
0
0

I always create an IConfig interface with typesafe properties declared for all configuration values. A Config implementation class then wraps the calls to System.Configuration. All your System.Configuration calls are now in one place, and it is so much easier and cleaner to maintain and track which fields are being used and declare their default values. I write a set of private helper methods to read and parse common data types.

Using an IoC framework you can access the IConfig fields anywhere your in application by simply passing the interface to a class constructor. You're also then able to create mock implementations of the IConfig interface in your unit tests so you can now test various configuration values and value combinations without needing to touch your App.config or Web.config file.


Viewing all articles
Browse latest Browse all 29

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>