1

I have a ASP.NET webapi project that references various class libraries(dlls) and each class library depends its own appsettings. The folder structure of the project is as shown below,

WebApiProject
|
+---- Dlls
       +---- ClassLibrary1
              ----- classlibrary1.dll
              ----- classlibrary1.dll.config
       +---- ClassLibrary2
              ----- classlibrary2.dll
              ----- classlibrary2.dll.config

When i include all the app settings from classlibrary1.dll.config to web.config there are no issues using classlibrary1 in webapi project. This approach falls a part when there are duplicate app settings between classlibrary1.dll.config and classlibrary2.dll.confg. I am looking something like dynamically load configuration based on the library i am about to use

Is there any way to load app settings dynamically before invoking a method from class library(dll)

Ramz
  • 11
  • 2
  • Libraries don't have .config files... only sites/apps. So you may want to rethink your design. Becoming an expert with assembly loading and configuration is another option - generally preferable from SO point of view as you'd be able to provide good answers. – Alexei Levenkov Jan 13 '21 at 04:40
  • @Alexei Levenkov - Agree on libraries don't have configuration files, the point here is each library depends its own app configuration, there are common configuration between two libraries hence adding them to web.config is not an option. – Ramz Jan 13 '21 at 05:01
  • `AppSettings` is a common configuration section used in different types of application. And also one configuration section can appear only once in a configuration file. So if you have multiple configuration files with the same Section, it won't work. You might want to different configuration sections for each of the class libraries. – Chetan Jan 13 '21 at 05:42
  • @Chetan Ranpariya "You might want to different configuration sections for each of the class libraries" Can you please more specific? an example how to do that? you mean in the web.config separate appsettings sections how? – Ramz Jan 13 '21 at 06:02
  • https://stackoverflow.com/questions/3935331/how-to-implement-a-configurationsection-with-a-configurationelementcollection – Chetan Jan 13 '21 at 07:00
  • https://ivankahl.com/creating-custom-configuration-sections-in-app-config/ – Chetan Jan 13 '21 at 07:00

0 Answers0