I am already working on a .net project but I think this question can apply to any programming language/framework.
The question is what are the good practices for reading configuration for a class library. I can think of the following options:
Any ideas/preferences?
Right-click on the solution in Solution Explorer and select Add > New Project. On the Add a new project page, enter library in the search box. Choose C# or Visual Basic from the Language list, and then choose All platforms from the Platform list. Choose the Class Library template, and then choose Next.
Procedure to Create a Class LibraryStart a new project in Visual Studio from the New Project dialogue box, select Class Library Template from the Project Template Window. In the Name box, type a name for your Class Library, say Calculator. Then click OK.
Surprisingly (or unsurprisingly?) it depends.
From a developer's point of view, having the caller supply configuration via library API is preferable because it allows the library to be used in a wider variety of contexts, not dependent on how the library is being hosted. Providing a configuration loader that can pull from app domain or a private file is gravy, and reasonably usable defaults if no configuration is performed are a sanity-saver.
From an operator's point of view, it is also useful to be able to override whatever settings a developer supplied because they don't make sense in your environment. It's not clear to me how this might work if the developer is deliberately trying to force the shape of the environment on you, though.
I think the best compromise is to allow for all three possibilities, as log4net does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With