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.