I am working on a class library(.NET Standard 2.0) CL, which will be used by some of our legacy projects(.NET Framework 4.6.1) LP and many of our new implementations(.NET Core 3.1) NI.
My class library CL needs some of the configuration settings but when it is being used by new implementations NI, CL receives Microsoft.Extensions.Configuration.IConfiguration
, as NI has appSettings.json
.
And when used from legacy projects LP, CL receives System.Configuration.ConfigurationManager.AppSettings
as LP has either of web.config
or app.config
.
Is there any elegant way to read configuration from both types of projects either .NET Framework or .NET Core? I don't want to read the configuration in projects like LP or NI who is consuming my library CL as that configuration is of no use to them.
private static void LoadConfiguration() // called from constructor
{
string receivedFromNETCore = configuration["DataMappingXml"];
// Microsoft.Extensions.Configuration.IConfiguration
string receivedFromNETFramework =
ConfigurationManager.AppSettings["DataMappingXml"];
// TODO: LOAD configuration and process.
}