ASP. NET -- Microsoft. NET Pet Shop 3.x( 2)

Source: Internet
Author: User

Learning PetShop3.x. Now I will write some of my summary.

PetShop3.x layers are clearly divided into the UI, Business Layer, Data Access Layer, and typical N-Layer architecture.

Great.

However, a closer look at the source code shows that it is not that simple and clear, because some easy-to-Expand functions are implemented when the Data Access layer is presented.

Architecture, then the factory model. so in order to find out it, I chose a specific function for research. The other functions are basically the same. I chose Product.

Let's take a picture first:


We can see that the Catagory of PetShop. Web calls the Product in the BLL layer,

The Code is as follows: it can be found in catagory. aspx. cs.

// Check to see if the contents are in the Data Cache

If (Cache [categoryKey]! = Null ){

// If the data is already cached, then used the cached copy

Products. DataSource = (IList) Cache [categoryKey];

} Else {

// If the data is not cached, then create a new products object and request the data

Product product = new Product ();

IList productsByCategory = product. GetProductsByCategory (categoryKey );


// Store the results of the call in the Cache and set the time out to 12 hours

Cache. Add (categoryKey, productsByCategory, null, DateTime. Now. AddHours (12), Cache. nosdomainingexpiration, CacheItemPriority. High, null );

Products. DataSource = productsByCategory;

}

How does PetShop. BLL. Product's GetProductsByCategory handle it?

Take a look at the following code

Public IList GetProductsByCategory (string category ){

// Return null if the string is empty

If (category. Trim () = string. Empty)

Return null;

// Get an instance of the Product DAL using the DALFactory

IProduct dal = PetShop. DALFactory. Product. Create ();

// Run a search against the data store

Return dal. GetProductsByCategory (category );


}


The above is the implementation code. We will find that PetShop. DALFactory is used, and this is the factory mode. Create an IProduct instance. In fact

At this time, it is created from PetShop. SQLServerDAL Product class, so PetShop is called. SQLServerDAL. product. getProductByCatagory method, instead of PetShop. oracleDAL. product. getProductByCatagory. I will discuss this later.

Speaking of this, I think I am familiar with how to call it.

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.