This may be the simple question to answer, but I am struggling to resolve.
I have Web.config
with the following values in my Web Application.
<appSettings>
<add key ="FirstName" value ="Prasad"/>
<add key ="LastName" value ="Kanaparthi"/>
</appSettings>
I have App.config
with following value in my Class Library (Say Lib).
<appSettings>
<add key ="FullName" value ="Prasad Kanaparthi"/>
</appSettings>
The class library(Lib) is pluggable component, I have added the Class Library(Lib) reference in my Web Application.
I have the below code in my Class Library(Lib). When i create instance for GetAppSettings
in my web application i can see below responses.
namespace Lib
{
public class GetAppSettings
{
public GetAppSettings()
{
var FirstName = ConfigurationManager.AppSettings["FirstName"]; // O/P : Prasad
var MiddleName = ConfigurationManager.AppSettings["LastName"]; // O/P : Kanaparthi
var FullName = ConfigurationManager.AppSettings["FullName"]; // O/P : null
}
}
}
The Question is how can i read FullName
from App.config
which is Class Library (Lib).
Note: Since my Lib is pluggable component, So the consumers can change the FullName
of their own. I cannot merge values to Web.confing
from App.config
.
You have to merge both configuration sections and place all settings in the main configuration file of your application. In case of the web applciation it would be the web.config
.
The short answer is: you can't. The application using your library won't pay any attention to your app.config
. You could use a settings
file instead or perhaps go a longer way around, abstract out the configuration manager and have it programmatically read your app.config
as an XML file in the application's output directory in order to include its settings. Understandably, neither option is ideal.
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