Well, you can use AppSettings and ConnectionStrings from a Web.config file into your class library. You might be thinking why should I use these objects from a web.config where as I already have App.config file resides in a C# class library. Well, the reason is, you might face some requirements like you want to create General APIs from class library and that can be used in a Website in which you allow user to provide its connection string and some app settings that will be used by this APIs. In this case end user will provide its connection string and all other settings in web.config file of his website. (No doubt, you need to provide static names of “Keys” that this library is using, so that your application runs smooth)
Now comming to the point; you can access AppSettings and ConnectionStrings objects by adding reference of System.Configuration.dll from .NET framework into your C# library Reference and include that namespace in your class file at the beggening like:
using System.Configuration;
Comments
Post a Comment