1

Let's say I have 2 projects in C#:

  • A class library project called Repository that encapsulates the database-access logic (implements CRUD methods to be consumed by any client). This project has an App.config file that defines a key called Username, with value user01.
  • An ASP.NET (for example, an MVC application) project called Website that uses the Repository project as a reference, and it consumes the methods provided by Repository. This project has a Web.config file that defines a key called Username, with value manager01.

The problem I've found out is that, when any Repository method retrieves the value of the Username key, it will not retrieve the value user01. If called from website, it'll retrieve the value manager01; if called from another project that does not have a key called Username in its own config file, it'll throw a NullReferenceException.

My queston is: how can I force the Repository project (or any project, for that matter) to use its own config's keys instead of the caller's config keys?

Léster
  • 1,177
  • 1
  • 17
  • 39
  • http://stackoverflow.com/questions/5190539/equivalent-to-app-config-for-a-library-dll – Matteo Umili Feb 03 '17 at 14:16
  • I added an answer in the duplicate question if you don't find a suitable answer: [http://stackoverflow.com/a/42026907/1351076](http://stackoverflow.com/a/42026907/1351076) – krlzlx Feb 03 '17 at 16:06

1 Answers1

0

Yes, you can include another .config file into the main project config file.

Obviously if you set like startup project a website, your application will read his .config file before.

Into that file use this for include another config file to read

<securityConfiguration configSource="AnotherConfigurationFile.config" />

PS: put the others config file all in the same folder.

Payedimaunt
  • 1,014
  • 2
  • 10
  • 23