Support multi-database access using the reflection factory Mode

Source: Internet
Author: User
Tags dot net dnn

Enabling application software to support multiple database operations is a requirement in application development software. In. net, we can use the classes provided in the system. Data. ODBC namespace to perform operations on all databases. However, in. net, it also provides unique data for different databases.Program. For example, to access the SQL Server database, you can use the class in the namespace of system. Data. sqlclient. To access the Oracle database, you can use the class in the namespace of system. Data. oracleclient. Use these unique database providers to achieve higher performance. Therefore, when developing software, we need to design a mode to support accessing a specific database using a specific database provider, rather than using ODBC connections.

The factory mode is a common method that supports multiple database operations. "Factory model" has many blogsArticleI will not talk about it here. In dotnetnuke (dnn), the reflection principle in. NET is used to simplify the factory classCodeAnd implements the function of dynamically creating object instances, avoiding the need to re-compile the main program for new database types. In dnn, configure the database access provider through the custom configuration node in the web. config configuration file, and set the default database access provider for the application. By modifying the configuration file, you can add and modify the specific database accessed by the application. In dnn, various database access providers inherit a data access factory class named dataprovider. This class dynamically constructs the default specific data access provider set in the configuration file.
The static structure is as follows:

I think the database access mode in dnn is worth learning. Therefore, I extract this part of dnn and rewrite it with C # for other projects. This is indeed a good way to share it with you. Please be sure to point out any problems. Of course there are still better methods. You can also write them out and share them.

Download demo>

Related content:
Dot Net Design Patterns-reflection Factory: http://fineboy.cnblogs.com/archive/2005/08/03/206244.html
This article details the principles of the reflection factory.

Dnn data access policies (http://michaelj.cnblogs.com/archive/2005/08/11/212532.html)

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.