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 calledUsername
, with valueuser01
. - 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 calledUsername
, with valuemanager01
.
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?