Petshop4.0 factory mode and profile provider implementation

Source: Internet
Author: User

Part 1: factory Model

I. Project Name and description: (implementation steps: 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 = Abstract Factory of the data layer (create reflection)
6. sqlserverdal = sqlserver data access layer/oracledal = ORACLE data access layer

Dbutility database access component basic class

2. Project Reference relationship
1. The web references BLL.
2. BLL references idal and model and uses dalfactory to create an instance.
3. The idal references the model.
4. The model is not referenced.
5. dalfactory references idal, reads the set assembly in Web. config, loads the class instance, and returns it to BLL for use.
6. sqlserverdal references model and idal, and is loaded by dalfactory to implement the methods in the interface.

3. Implementation steps
1. Create a model to implement business entities.
2. Create an idal to implement the interface.
3. Create sqlserverdal to implement the methods in the interface.
4. Add the configuration information in Web. config as the sqlserverdal assembly.
5. Create dalfactory and return the instance of the specified class of the Assembly.
6. Create BLL and call dalfactory to obtain the instance of the specified class of the assembly and complete the data operation method.
7. Create a web and call the data operation method in BLL.

Note:
1. The Assembly name in Web. config must be consistent with the output Assembly name in sqlserverdal.
2. Only one dataaccess class is required in dalfactory to create all Assembly instances.
3. After the project is created, modify the default namespace and Assembly name for each project.
4. Pay attention to modifying project dependencies in the solution.
5. Add project references in the solution.

Part 2: Use of profile (also factory method)
Overview: the profile of petshop is implemented through its own profileprovider.

I. Project Name and description
1. Data access layer of profile = Profile
2. factory class of profiledalfactory = profiledal (reflection creates profiledal)
3. Data access layer interface definition of iprofiledal = Profile
4. sqlprofiledal = SQL server profile providers for user status management

2. Project Reference relationship
1. Profile references profiledalfactory, iprofiledal, and model. Use the profiledalfactory method to create an assembly instance.
2. profiledalfactory references iprofiledal. The method to implement the Assembly instance.
3. iprofiledal references the model. Implementation interface.
4. sqlprofiledal references model and iprofiledal. The Assembly loaded by profiledalfactory implements the methods in the interface.

3. Implementation steps
1. Create a model to implement business entities.
2. Create iprofiledal to implement the interface.
3. Create sqlprofiledal to implement the methods in the interface.
4. Add the configuration information in Web. config as the sqlprofiledal assembly.
5. Create profiledalfactory and return the instance of the specified class of the Assembly.
6. Create a profile to implement profile provider.
7. Add the configuration section profile in the web. config file, add attributes and types, and set provider to profile.
Example:
<System. Web>
<Profileautomaticsaveenabled = "false" defaultprovider = "default profile provider">
<Providers>
<Addname = "name of your own provider" connectionstringname = "Name of the database link in the configuration file" type = "your provider implementation class, you need to override "applicationname =" your application name "/>
</Providers>
<Properties>
<Addname = "name of your own profile" type = "your class, you need to build" allowanonymous = "false" provider = "name of your own provider above"/>
</Properties>
</Profile>
</System. Web>

Note:
1. the type of profile can be its own class, including business instances or methods.
2. rewrite some methods in profileprovider to record the desired personalized user information in your database.
3. If each user has a large amount of data information, such data information should not be recorded through profile.
4. For a type defined as profile, you must add [serializable] before the class definition to implement serialization.
5. the type defined by the interface must be a class.
6. the reference of system. Web. Profile and system. configuration must be added to the project in the profile provider class.
7. To support anonymous users, add <anonymousidentification enabled = "true"/> to Web. config, which is in the range of profiles.
8. After the profile. Save method is used, the method in profiledalfactory is called to save the data to the database.

Because the above content is converted from the HTML format, some code may be lost. Please download the HTML source file:

Part 1: factory Model

I. Project Name and description: (implementation steps: 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 = Abstract Factory of the data layer (create reflection)
6. sqlserverdal = sqlserver data access layer/oracledal = ORACLE data access layer

Dbutility database access component basic class

2. Project Reference relationship
1. The web references BLL.
2. BLL references idal and model and uses dalfactory to create an instance.
3. The idal references the model.
4. The model is not referenced.
5. dalfactory references idal, reads the set assembly in Web. config, loads the class instance, and returns it to BLL for use.
6. sqlserverdal references model and idal, and is loaded by dalfactory to implement the methods in the interface.

 

3. Implementation steps
1,
Create a model to implement business entities.
2,
Create an idal to implement the interface.
3,
Create sqlserverdal to implement the methods in the interface.
4,
Add the configuration information in Web. config as the sqlserverdal assembly.
5,
Create dalfactory and return the instance of the specified class of the Assembly.
6,
Create Bll, call dalfactory, get the instance of the specified class of the Assembly, and complete the data operation method.
7,
Create a web and call the data operation method in BLL.

Note:
1. The Assembly name in Web. config must be consistent with the output Assembly name in sqlserverdal.
2. Only one dataaccess class is required in dalfactory to create all Assembly instances.
3. After the project is created, modify the default namespace and Assembly name for each project.
4. Pay attention to modifying project dependencies in the solution.
5. Add project references in the solution.

Part 2: Use of Profile(Also factory method)
Overview: the profile of petshop is implemented through its own profileprovider.

I. Project Name and description
1. Data access layer of profile = Profile
2. factory class of profiledalfactory = profiledal (reflection creates profiledal)
3. Data access layer interface definition of iprofiledal = Profile
4. sqlprofiledal = SQL server profile providers for user status management

2. Project Reference relationship
1. Profile references profiledalfactory, iprofiledal, and model. Use the profiledalfactory method to create an assembly instance.
2. profiledalfactory references iprofiledal. The method to implement the Assembly instance.
3. iprofiledal references the model. Implementation interface.
4. sqlprofiledal references model and iprofiledal. The Assembly loaded by profiledalfactory implements the methods in the interface.

3. Implementation steps
1,
Create a model to implement business entities.
2,
Create iprofiledal to implement the interface.
3,
Create sqlprofiledal to implement the methods in the interface.
4,
Add the configuration information in Web. config as the sqlprofiledal assembly.
5,
Create profiledalfactory and return the instance of the specified class of the Assembly.
6,
Create a profile to implement profile provider.
7,
Add the configuration section profile in the web. config file, and add attributes and types. The provider is the profile.
Example:
<System. Web>
<Profileautomaticsaveenabled = "false" defaultprovider = "default profile provider">
<Providers>
<Addname = "name of your own provider" connectionstringname = "Name of the database link in the configuration file" type = "your provider implementation class, you need to override "applicationname =" your application name "/>
</Providers>
<Properties>
<Addname = "name of your own profile" type = "your class, you need to build" allowanonymous = "false" provider = "name of your own provider above"/>
</Properties>
</Profile>
</System. Web>

Note:
1. the type of profile can be its own class, including business instances or methods.
2. rewrite some methods in profileprovider to record the desired personalized user information in your database.
3. If each user has a large amount of data information, such data information should not be recorded through profile.
4. For a type defined as profile, you must add [serializable] before the class definition to implement serialization.
5. the type defined by the interface must be a class.
6. the reference of system. Web. Profile and system. configuration must be added to the project in the profile provider class.
7. To support anonymous users, add <anonymousidentification enabled = "true"/> to Web. config, which is in the range of profiles.
8. After the profile. Save method is used, the method in profiledalfactory is called to save the data to the database.

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.