c# - What is the best way to create a Utility dll that can be configured by consuming application? -
i have created dll has functionality in shared project project. however, may need adjust settings of dll project referencing it. best way expose configuration settings dll used project in entirely different solution?
ways have tried:
appsettings import
applicationsettings import
current setup, consuming solution setting values ignored/not set, why?
dll setting
public class applicationsettingsretriever : iapplicationsettingsretriever { public string logenvironmentsetting => configurationmanager.appsettings.get("logenvironment"); }
consumer solution app.config
<?xml version="1.0" encoding="utf-8"?> <configuration> <runtime> <assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentassembly> <assemblyidentity name="newtonsoft.json" publickeytoken="30ad4fe6b2a6aeed" culture="neutral" /> <bindingredirect oldversion="0.0.0.0-9.0.0.0" newversion="9.0.0.0" /> </dependentassembly> </assemblybinding> </runtime> <appsettings> <add key="logenvironment" value="local"/> </appsettings> </configuration>
you don't need import anything. in .net, dll obtains configuration settings parent application, not own config. example if need dll read connection string parent application's configuration, can use
return configurationmanager.appsettings["connectionstring"];
this read custom configuration section in app.config
containing windows application, or web.config
if it's web application.
Comments
Post a Comment