In the first part, we learned ASP. NET provider The basic concepts of the model. ASP. NET Built-in Provider The framework of the model. For details, we will discuss Membership Of Provider Model
Membership providerBasic Class
First, let's look at the following figure.
As you can see, all Provider The basic classes of the model are Providerbase . Providerbase Class resident in System. configuration. dll In System. configuration. Provider In the namespace Class is marked Abstract It can be used as a template for the successor. The An important method is Initalize () . This method is usually used from the configuration file Web. config Read configuration information and initialize Provider Model
MembershipproviderClass resident inSystem. Web. SecurityIn a namespace, this class is composedProviderbase classInherited and added the feature methods and attributes required by the member relationship (these methods and attributes are used to establish and manage user-specific), The class is also markedAbstract.
Finally, Sqlmembership Class resident in System. Web. Security Namespace, which is from Membershipprovider Class. This is a specific class that can be executed from Providerbase And Membershipprovider Defined specifically for execution SQL Server Database attributes and methods.
OtherProviderClass
Similar class inheritance relationships can be found in SQL role , SQL profile provider See in the model. For example SQL role provider The link chain of the inherited model is as follows:
Providerbase --> roleprovider--> Sqlroleprovider
SQL profile providerThe inherited model chain of is as follows:
Providerbase-> settingsprovider-> profileprovider-> sqlprofileprovider
Select an abstract class or an Interface
In ASP. net2.0 You can see the change in Microsoft's design guidelines. In . Net2.0 In earlier versions, they usually use more dependent interfaces to provide template models for framework classes, such Ado. net1.x Data in Provider Class is to execute a common interface ( Idbconnection, idbcommand ). Although Ado. net2.0 continues These interfaces are supported, but this may be for compatibility reasons.
InAdo. net2.0They prefer to select abstract classes.ProviderThe abstract class is used. Instead of using the template generated by the interface, select an abstract class. The possible reasons are:
Abstract classes can execute certain functions, while interfaces cannot.
After the interface is defined, it is not easy to change because the changes will damage the classes defined from the interface.
Abstract classes are used, and the base classes can be non-interfering subclass.
Summary: This document provides an in-depth introductionASP. NET providerModel. In the next part of this series, we will use the first, 2Part of the knowledge comes from defining your ownMembershipModel