PetShop4.0 Factory mode and profile provider implementation

Source: Internet
Author: User
Tags class definition reflection

PetShop4.0 Factory mode and profile provider implementation

Part I: Factory model

First, the project name and Description: (Realization step: 4-3-6-5-2-1)
1, web= presentation layer
2. bll= Business Logic Layer
3. idal= data Access Layer Interface definition
4. model= Business Entity
5, dalfactory= the data layer of the abstract factory (create reflection)
6. Sqlserverdal=sqlserver data Access Layer/oracledal=oracle data access Layer

Dbutility Database Access Component base class

Second, project reference relationship
1, Web reference BLL.
2, BLL reference Idal,model, use Dalfactory to create an instance.
3, Idal reference Model.
4, Model without reference.
5, Dalfactory reference Idal, by reading the web.config set in the assembly, load the instance of the class, return to BLL use.
6, Sqlserverdal Reference Model and Idal, Dalfactory loaded assembly, implementation of the method in the interface.

Full text Source: http://www.cnblogs.com/howsmile/archive/2006/09/18/507524.aspx

Third, the realization step
1. Create model to realize business entity.
2, create idal, implement interface.
3, create Sqlserverdal, implement the method in the interface.
4, increase the configuration information in the web.config, for the Sqlserverdal assembly.
5, create dalfactory, return an instance of the assembly's specified class.
6. Create BLL, call Dalfactory, get an instance of the assembly-specified class, and complete the data manipulation method.
7, create the Web, call the BLL in the data operation method.

Attention:
1, the assembly name in the web.config must be the same as the output assembly name in Sqlserverdal.
2, dalfactory only need a dataaccess class, you can complete the creation of all the assembly instances.
3. After the project is created, be careful to modify the default namespace and assembly name for each purpose.
4, pay attention to modify the project dependencies in the solution.
5. Note that the project references are added to the solution.

Part II: Use of profile (also factory method)


Overview: PetShop's profile is implemented by its own profileprovider.

I. Name and description of the project
1, profile=profile data access layer
2, Profiledalfactory=profiledal factory Class (reflection creation Profiledal)
3, Iprofiledal=profile data Access layer Interface definition
4, Sqlprofiledal=sql Server profile Providers to do User state management

Second, project reference relationship
1, profile reference Profiledalfactory,iprofiledal,model. Create an assembly instance through the Profiledalfactory method.
2, profiledalfactory reference iprofiledal. The method that implements the assembly instance.
3, Iprofiledal reference Model. Implement the interface.
4, Sqlprofiledal reference Model,iprofiledal. The assembly that is loaded by profiledalfactory implements the methods in the interface.

Third, the realization step
1. Create model to realize business entity.
2, create iprofiledal, implement interface.
3, create Sqlprofiledal, implement the method in the interface.
4, increase the configuration information in the web.config, for the Sqlprofiledal assembly.
5, create profiledalfactory, return an instance of the assembly's specified class.
6, create profile, to achieve profile Provider.
7, in the Web.config file to add configuration section profile, add attributes and types, provider profile.
Cases:
<system.web>
<profileautomaticsaveenabled= "false" defaultprovider= "default profile Provider" >
<providers>
<addname= "Provider name" Connectionstringname= "the name of the database link in the profile" Type= "your own provider implementation class, you need to override" Applicationname= "yourself Your own defined application name "/>
</providers>
<properties>
<addname= "own named Profile name" Type= "own class, need to build" allowanonymous= "false" provider= "above named Provider name"/>
</properties>
</profile>
</system.web>

Note:
1, Profile type can be its own class, including business instances or methods, and so on.
2, by rewriting some of the methods in the ProfileProvider to record the personalized user information you want in your own database.
3, if each user has a large number of data information, then this type of data information should not be recorded through profile.
4, a class that is defined as the type of profile, must add [Serializable] before the class definition to achieve serializable.
5, the type of the interface definition must be a class.
6, the profile provider class must add System.Web.Profile and System.Configuration references to the project.
7, if you need to support anonymous users, add <anonymousidentification enabled= "true"/> to Web.config, between profile.
8, after using the Profile.save method, the method in the Profiledalfactory is invoked to save the data to the database.   &NBSP;

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.