[Entlib] Microsoft Enterprise Library 5.0 learning path-Step 8. Use the configuration setting module and other methods to classify and manage Enterprise Library configuration information

Source: Internet
Author: User

After introducing several common modules of the enterprise database, I want to process the configuration file of the enterprise database today because I open the web. config finds the web when you want to perform some configuration. config has changed to abnormal bloated (A large amount of enterprise database configuration information is filled), So I decided to write this article about the configuration setting module and other methods to manage the Enterprise Library configuration information by category.Article.

In ASP. net4, Microsoft helped us optimize web. config and gave us a clean web. config (RegisterProgramSet, ASP. NET label, and handler are all moved to machine. config.This greatly facilitates our developers.

Although we can easily configure the enterprise database information through the enterprise database configuration tool. modifying other information in config is troublesome, and the information of each module in the enterprise database is not conducive to future maintenance. Therefore, we must first strip out the configuration information of the enterprise database, then the modules are divided into independent ones. the Config configuration file is put in a folder, so that you can immediately find the file to be configured when you modify the configuration information after the project is released.

There are three main ways to separate configuration files. Each of these three methods has its own advantages and disadvantages, mainly depending on how it is applied.:

1. Use the configuration setting (Configuration is not requiredCodeThe isolated modules cannot be viewed in a unified manner, but can only be viewed in a separate module. Recommended)

2. Separate the independent config file or use the encoding to read the configuration file (Code must be written, which is difficult to use. The isolated modules cannot be viewed in a unified manner and can only be viewed in separate modules. This is not recommended.)

3. Use the. NET configsource feature for configuration (You do not need to configure the enterprise database tool. You only need to separate the code. The isolated modules can be viewed in a unified manner. However, after modifying the configuration file, all the configuration information will return to the Web. in config, separate configuration files cannot be modified. We recommend that you)

 

1. Use the configuration setting module provided by default in the enterprise database for configuration:

1. First, separate the information of each module into a separate config file (Including the section of this module and specific configuration) As follows (data access module configuration file ):

<? XML version = "1.0"?> <Configuration> <configsections> <section name = "dataconfiguration" type = "Microsoft. practices. enterpriselibrary. data. configuration. databasesettings, Microsoft. practices. enterpriselibrary. data, version = 5.0.414.0, culture = neutral, publickeytoken = require "requirepermission =" true "/> </configsections> <dataconfiguration defaultdatabase =" entlibstudy "/> <connectionstrings> <Add name =" entlibstudy "connectionstring =" Server = sql2005; database = entlibstudy; Integrated Security = true; "providername =" system. data. sqlclient "/> <Add name =" entlibstudysqlite "connectionstring =" Data Source = | datadirectory | entlibstudysqlite. db3 "providername =" system. data. SQLite "/> </connectionstrings> </configuration>

2. Add a configuration setting module to the enterprise database, select Add a filed-based configuration source, select the path as the separated config configuration file, and create a redirection setting, set to the corresponding enterprise database module:

Add filed-based configuration Source

Point to the configuration file and create a reset Module

 

 

In this way, there are several Enterprise Library modules in the project to create several corresponding configuration files, and no code needs to be modified.

 

2. Use the encoding format for Configuration:

The configuration file used in this method is the same as the first method. The configuration file must contain the configuration information of sections and other modules, and then the following code is used when the modules of the enterprise are used:

// Cache module // create a fileconfigurationsource to read the configuration file fileconfigurationsource cachedatasource = new fileconfigurationsource ("cache. config "); // read the file configuration source from the module Factory: cachemanagerfactory = new cachemanagerfactory (cachedatasource); // create a specific module instance, icachemanager cachemanager = cachemanagerfactory. create ("cache manager"); cachemanager. add ("test", "test"); // data access module fileconfigurationsource dbdatasource = new fileconfigurationsource ("data. config "); databaseproviderfactory = new databaseproviderfactory (dbdatasource); database DB = databaseproviderfactory. create ("entlibstudy ");

I personally think this method is inconvenient. Every time you use a module in the Enterprise Library, you must first obtain the specific configuration information of this module through fileconfigurationsource before you can create an instance object, if the configuration file name is changed, an exception occurs. Therefore, this method is not recommended for configuration information management.

 

3. Use the. NET configsource feature for configuration:

The advantage of this method is that you do not need to add configuration setting to the enterprise database. You only need to create a config file separately and then cut the required configuration information into the config file, note the following points:

1. The section information about the Enterprise Library module must be placed in Web. config.

2. The separately placed config file should be a clean XML file and cannot contain the <configuration> Configuration section. You only need to configure a module.

3. In web. config, you must retain the configuration section pointing to config.

Although this method is the best, but the disadvantage is also very prominent, that is, once the Web is modified through the Enterprise Database Configuration tool. config. the separate config file cannot be edited separately.

The specific configuration is as follows:

Web. config:

 
<Cachingconfiguration configsource = "configs/cacheconfig. config"/>

Cacheconfig. config:

 
   
   
    
     
    
    
     
    
   

This completes the configuration, without any changes in the Code, and allows you to view the specific configuration information in the enterprise database configuration tool, the only bad thing is that once you use the Enterprise Library Configuration tool to open the web. after the congfig file, all the configuration information that is separated from each configuration file is returned to the Web again. config, it can be said that there are advantages and disadvantages.

 

The above three methods are the classification processing method of enterprise database configuration information. In general, the recommended sequence is: first type> third type> second type. However, the specific method should be selected based on various usage requirements.

 

Source codeDownload: Click here to download

 

Note:

1. The MSSQL database is in the database directory (you need to attach the database yourself), and The SQLite database is in the app_data directory of the web directory. Because of the project size, the bin directory of each project has been deleted, if a project cannot be generated, add the DLL of the relevant enterprise library.

2. As Microsoft enterprise database 5.0 is a learning path, this series is intended to introduce the modules of the enterprise database in the form of a small project, so the source code will be updated according to the updates in the series of articles, therefore, the source code cannot be the same as the Code posted in the article.

3. The project development environment is vs2010 + sql2005.

4. Administrator Account: Admin

Password: Admin

 

Index of a series of articles on the learning path of Microsoft enterprise database 5.0:

Step 1: getting started

Step 2: Use the vs2010 + data access module to create a multi-database project

Step 3: Add exception handling to the project (record to the database using custom extension)

Step 4: Use the cache to improve the website's performance (entlib caching)

Step 5: Introduce the entlib. validation module information, the implementation level of the validators, and the use of various built-in validators-Part 1

Step 5: Introduce the entlib. validation module information, the implementation level of the validators, and the use of various built-in validators-Part 1

Step 5: Introduce the entlib. validation module information, the implementation level of the validators, and the use of various built-in validators-Part 2

Step 6: Use the validation module for server-side data verification

Step 7: Simple Analysis of the cryptographer encryption module, custom encryption interfaces, and usage-Part 1

Step 7: Simple Analysis of the cryptographer encryption module, custom encryption interfaces, and usage-Part 2

Step 8. Use the configuration setting module and other methods to classify and manage enterprise database configuration information

Step 9: Use the policyinjection module for AOP-PART1-basic usage

Step 9: Use the policyinjection module for AOP-PART2-custom matching rule

Step 9: Use the policyinjection module for AOP-PART3 -- Introduction to built-in call Handler

Step 9: Use the policyinjection module for AOP-PART4 -- create a custom call handler to achieve user operation Logging

Step 10: Use unity to decouple your system-Part1-Why use unity?

Step 10: Use unity to decouple your system-Part2-learn how to use Unity (1)

Step 10. Use unity to decouple your system-Part2-learn how to use Unity (2)

Step 10: Use unity to decouple your system-Part2-learn how to use Unity (3)

Step 10: Use unity to decouple your system-Part3-dependency Injection

Step 10: Use unity to decouple your system-part4 -- unity & piab

Extended learning:

Extended learning and dependency injection in libraries (rebuilding Microsoft Enterprise Library) [go]

 

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.