Enterprise Library Step by Step Series (ii) Configure the application Block

Source: Internet
Author: User
Tags configuration settings

A Response Configuration Change Notification:

The Configuration Application Block provides an event mechanism that notifies the application when the stored configuration changes, using the steps:

1) Create a Evernthandler

1/**////<summary>
2///Create Eventhanler
3///</summary>
4///<param name= "se NDEr "></param>
5///<param name=" args "></PARAM>
6 private void onconfigurationchanged ( object sender, Configurationchangedeventargs args)
7 {
8 Cursor = System.Windows.Forms.Cursors.WaitCursor;
9
Editorfontdata configdata = configurationmanager.getconfiguration ("Editorsettings") as EditorFontData;< br>
StringBuilder results = new StringBuilder (),
results. Append ("Configuration changes in storage were detected. Updating configuration. ");
Results. Append (Environment.NewLine);
Results. Append ("New Configuration settings:");
Results. Append (Environment.NewLine);
Results. Append (' t ');
Results. Append (Configdata.tostring ());
Results. Append (Environment.NewLine);

Cursor = System.Windows.Forms.CursoRs. Arrow;
}

2) Registration Event

1/**////注册事件
2    ConfigurationManager.ConfigurationChanged += new ConfigurationChangedEventHandler(OnConfigurationChanged);

Two To configure data caching:

Configuration Application Block provides a cache of configuration data at design time, reading the XML data, reading it again first determines whether the cache is empty, and if not, it reads the data directly from the cache (detailed in the profiling article).

Explicitly erase the cache with the following code:

1/**////清除缓存数据
2     ConfigurationManager.ClearSingletonSectionCache();

Three Extension mechanisms for senior staff:

1. In addition to using XML files to store data, you can also create your own storage methods, such as SQL Server Database, registry storage, and so on, we need to create our own storageprovider. To create a custom storage Provider, you need to be aware of the following points:

1 to read and write data, you need to inherit from the Storageprovider class and implement the Istorageproviderreader and Istorageproviderwriter interfaces separately:

1public class XmlFileStorageProvider : StorageProvider, IStorageProviderWriter
2    {
3      //……
4    }

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.