Use XXX. dll. config

Source: Internet
Author: User

If you need to configure the released DLL file, you can transfer the configuration information to app. config. Of course, you can also directly use the configuration in XXX. dll. config without transferring it. Of course, you must ensure thatProgramThe execution directory already contains the XXX. dll. config file.

CodeAdded the file monitoring cache.

View code

 Using  System;  Using  System. Collections. Generic;  Using  System. LINQ;  Using  System. text;  Using  System. configuration;  Using System. reflection;  Using  System. IO;  Using  System. Web. caching;  Using  System. Web;  Namespace  DOTNET. A. Core {  Public   Sealed   Class  Modelsetting {  Public   Static   String Getsetting ( String  Key ){  Return Assembly. getexecutingassembly (). Location + "  . Config  "  ;}  Public   Static   String Getsetting ( String Name, String  Defv ){  If (! Config. etettings. settings. allkeys. Contains (name )) Return  Defv;  Return  Config. etettings. settings [name]. value ;}  Public   Static   String  Modelconnstring {  Get  {  Return Config. connectionstrings. connectionstrings [ "  Dbserp "  ]. Connectionstring ;}}  Public   Static   String  Connstring {  Get  {  Return Config. connectionstrings. connectionstrings [ "  Connstring  "  ]. Connectionstring ;}}  Private  Static  Configuration config {  Get  {  VaR _ Config = httpruntime. cache [ "  _ Config  " ] As  Configuration;  If (_ Config = Null  ){  VaR Filemap = New  Execonfigurationfilemap (); filemap. execonfigfilename = Assembly. getexecutingassembly (). Location + "  . Config  "  ; _ Config = Configurationmanager. openmappedexeconfiguration (filemap, configurationuserlevel. None );  VaR Filecachedep = New  Cachedependency (filemap. execonfigfilename); system. Web. httpruntime. cache. Add ( "  _ Config  " , _ Config, filecachedep, cache. noabsoluteexpiration, cache. noslidingexpiration, cacheitempriority. High, Null  );}  Return  _ Config ;}}}} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.