Tag Info

New answers tagged


Only your program should know that appsettings exists. read it out and pass it in to your other objects. Easy public class Program { static void Main(string[] args) { var projectLog = ConfigurationManager.AppSettings["ProjectLog"]; FileLogger logger = new FileLogger(projectLog); ...


My question is since the values in the app.config file are used in many of my other classes do I have to instantiate ApplicationConfiguration in every class that may need my config values like so? No, because you do not want duplicated code and would refactor this into a super class. The real question is if it is even possible to create the instance ...


This seems like a good use case for the singleton pattern. Basically, it allows you to have a single class that is created once throughout the lifetime of the system, that gets created when it is accessed. Here's a simple example: public sealed class Configuration { private static Configuration instance = null; private static readonly object ...


If you are sure that your configuration setting stuff is not likely to change much, then you can wrap your configuration class in the sometimes-maligned "static" modifier like so: namespace ConsoleAppName { class Program { static void Main(string[] args) { var _projectLog = MyAppConfiguration.LogLocation; } } ...


Like @theatlasroom mentioned use some technique to structure your config-parameters. When that is in place, and since the parameters are "sensible to change" you might consider building some interface for editing them. Having one, it can guard against unreasonable or harmful values (some times entered by mistake) giving the user guidance.


YAML, JSON or XML are often used in frameworks for managing config settings. Depending on the language you are using, another option can be to use a structured entity (ie in a OO language using a class) to hold your config settings.

Top 50 recent answers are included