Dnn data access method-reasonable use mode to improve data access flexibility (with correction)

Source: Internet
Author: User
Tags dnn dotnetnuke
Note: I am looking at the design patterns. After careful understanding, I found that the data access method in dnn should be a simple factory model. (I can see some books saying that it is a reflection factory, I think he uses it. net reflection technology instantiates a simple factory of objects, hope not to make mistakes again), detailed descriptions will be explained in another article. I hereby declare that we will not mislead you. (2005-06-23)

The Data Access Method of dnn core framework tables is implemented by combining singleton and abstract factory. (The data access method for each user module seems to be the same)
Singleton: Used to ensure Program There is only one data access point.
Abstract Factory: provides an interface for creating a series of related or mutually dependent objects without specifying their specific classes.
Dataprovider (Components \ providers \ data \ dataprovider. VB) is such an abstract class, which provides all the interfaces required by the system to access database operations, sqldataprovider (providers \ dataproviders \ sqldataprovider. VB) is a subclass of dataprovider, which provides specific implementation for accessing the sqlserver database. You only need to call "dataprovider. instance (). method to be used. As for the type of subclass returned, the constructor in the dataprovider class calls createprovider () to dynamically construct a specific subclass.
The configuration of the subclass that is dynamically constructed is completely set by the user in the configuration file. For example: <! -- The default provider of data is sqldataprovider. -->
< Data Defaultprovider = "Sqldataprovider" >
< Providers >
< Clear />
<! -- Provider details -->
< Add Name = "Sqldataprovider" Type = "Dotnetnuke. Data. sqldataprovider, dotnetnuke. sqldataprovider" Connectionstringname = "Sitesqlserver" Upgradeconnectionstring = "" Providerpath = "~ \ Providers \ dataproviders \ sqldataprovider \" Objectqualifier = "" Databaseowner = "DBO"   />
</ Providers >
</ Data >

In this way, if you need to use the Oracle database, you only need to write an oracledataprovider subclass to implement the interfaces in dataprovider. Modify the configuration file information as follows. < Data Defaultprovider = "Oracledataprovider" >
< Providers >
< Clear />
<! -- Provider details -->
< Add Name = "Oracledataprovider" Type = "Dotnetnuke. Data. oracledataprovider, dotnetnuke. oracledataprovider" Connectionstringname = "Sitesqlserver" Upgradeconnectionstring = "" Providerpath = "~ \ Providers \ dataproviders \ oracledataprovider \" Objectqualifier = "" Databaseowner = ""   />
</ Providers >
</ Data >

This data access method allows you to flexibly configure the databases used by applications. Each user module has its own dataprovider, which enables different user modules to use different databases. I am still looking at the system framework. It is not certain whether different user modules can use different databases, but I think so.

More>

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.