(2) dotnet open-source e-commerce system-brnshop VS nopCommerce (two sets of dotnet e-commerce to PK-Article 2: Where should the code start-BrnMall3.0Beta) and php open-source e-commerce system

Source: Internet
Author: User
Tags nopcommerce

(2) dotnet open-source e-commerce system-brnshop VS nopCommerce (two sets of dotnet e-commerce to PK-Article 2: Where should the code start-BrnMall3.0Beta) and php open-source e-commerce system

Looking at the source code of the bulls, it is a little difficult for average-level people. I have written a stray phrase from my own code reading experience, hoping to make progress together with you and make future reference.

 

First, let's look at the source code structure of brnMall. Where should we start from?

First, we recommend that you take a look at the official analysis: BrnShop open-source online marketplace 2: ASP. net mvc Framework

The official article focuses on the following points:

(1) how to obtain the context of the web page environment, how to save it, and how to access it during brnshop design (the Controller's base class is reloaded for intercepting preprocessing during http access, identity authorization, authentication, and other issues.

(2) In order to conveniently obtain the context and automatically convert the corresponding type, you need to rewrite the WebViewPage page of mvc. Some readers may be confused here. Here, I have some knowledge about the bottom layer of mvc. I found some information to understand it. Document url: Razor engine of ASP. net mvc: View Compilation Principle

Simply put: A View is eventually compiled into a class. The base class of this class can be defined as the derived class of the WebViewPage class, so context type conversion can be completed in this derived class, and replace it with the base class of the view page. Of course, after making a custom replacement, remember to modify the relevant configuration so that mvc can use the derived class of your custom view page as the base class to generate the page.

(3) In addition, when reading the code, place the division of the Code.

(A) brnMall. data is mainly a database entity class (dealing with various table objects), brnMall. core is mainly the interface and policy configuration management class (such as mail interface and configuration, order interface and configuration) used by business logic and auxiliary functions, brnMall. the Service is the specific implementation of the business logic.

(B) when reading the presentation of the monetization layer, the key point is to read two points:

First, how does the author of the custom transformation on the Framework do it? In BrnMall. web. in the Framework, the Controller base class of each home page module is derived from the Controller, and the webpage context information is automatically recorded in the derived class. In this way, a user can automatically obtain a lot of information when accessing the homepage of the page, such as the browser type and whether the user is a mobile device. In ViewPages, automatic conversion is performed on the retrieved context for the type returned. In Pager, the page is mainly processed. Validator encapsulates the logic of Information validity check and the use of regular expressions. Theme is a Theme style issue that has not been thoroughly read yet and will be analyzed later.

Second, when we look at the code, we generally want to know the starting point of the program and the jump logic. We know that the mvc program has a startup project, and BrnMall. Web is the startup project, which serves as the starting point of the program in its Global. asax.

Namespace BrnMall. web {public class BrnMallApplication: System. web. httpApplication {protected void Application_Start () {// Replace the default view engine with ThemeRazorViewEngine ViewEngines. engines. clear (); ViewEngines. engines. add (new ThemeRazorViewEngine (); // register all regions/* AreaRegistration. registerAllAreas () is global. called in asax, it will find all AreaRegistration subclasses, * Whether in a Web project or in other class library projects. So we put a subclass of AreaRegistration in the project's Api folder, * can also be found, and then pass the namespace of the Controller in the parameter when registering the Area, the problem is solved. */AreaRegistration. registerAllAreas (); RouteConfig. registerRoutes (RouteTable. routes); // enable the event mechanism BMAEvent. start (); // reset the online user table if (Environment. tickCount> 0 & Environment. tickCount <900000) OnlineUsers. resetOnlineUserTable ();}}}

BrnMall has made many replacements and settings when it is started here, such as view engine and route table registration. Here is an important setting: AreaRegistration. RegisterAllAreas ();

What is the role of this code? In the same solution, different projects use different Areas and regions. The jump and call methods of each project Area are related to the area and route writing method. What does this mean? For example, if a user accesses BrnMall through a mobile phone, how does it display the page? First, it is in the Index method of the main area, that is, the BrnMall. Web controller HomeController.

/// <Summary> /// homepage controller class /// </summary> public partial class HomeController: baseWebController {// <summary> /// homepage // </summary> public ActionResult Index () {// determines whether the request comes from a mobile device, if yes, redirect to the mobile theme if (WebHelper. getQueryInt ("m ")! = 1 & WebHelper. isMobile () return RedirectToAction ("index", "home", new RouteValueDictionary {"area", "mob "}}); // The data on the home page needs to be directly called in its View file, so the View model return View ();} is no longer required here ();}}View Code

In this method, it determines whether the context is a mobile device. If so, it will jump to the index method of the controller with the same name on the Area of the mobile project.

// Determine whether the request comes from a mobile device. If yes, the request is redirected to a mobile topic.
If (WebHelper. GetQueryInt ("m ")! = 1 & WebHelper. IsMobile ())
Return RedirectToAction ("index", "home", new RouteValueDictionary {"area", "mob "}});

This Code uses the knowledge of how to jump to an Area and how to define an Area. There are two ways to define an Area. One is to add an Area to the same project, and the other is to have different areas in different projects of the same solution.

BrnMall is the second structure. It has a file: AreaRegistration in each project that is not the main Area and has an interface view. cs file, this file defines the AreaRegistration class derived class, in which it specifies the name of the Area and the routing method. Finally, you can automatically find all the defined areas and corresponding routing methods by calling AreaRegistration. RegisterAllAreas (); at the beginning of the program. This is another thing to pay attention. The following is a reference online article.

. NET/ASP. net mvc (AraeRegistration) MVC-RedirectToAction jump to other areas

Let's write it here today. Next time we will read the starting point structure analysis of nopCommerce, it is a bit stressful, because it feels that the code is hard. Try your best!

If you are willing to make friends, you can add me QQ: 9200118

 

Related Article

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.