Look at the source of Daniel, for the level of ordinary people, or slightly a bit difficult. I read the code from my own experience, write down the miscellaneous language, I hope to make progress together with you, but also for future memory of the reference.
First look at the source structure of the brnmall, from where to look at it?
The first recommendation to see is certainly the official analysis: Brnshop Open Source Online Mall second: ASP. NET MVC Framework
The official article is mainly about the points:
(1) How the context of the Web environment is acquired by the Brnshop design, how it is saved, and how it is accessed (overloading the base class of the controller for intercepting preprocessing, authorization, and authentication of HTTP access), which is the usual way of the MVC program customization.
(2) in order to conveniently obtain the context and automatically convert the corresponding type, you need to rewrite the Webviewpage page of MVC. It may be unclear to some of the readers here that there is some understanding of the underlying MVC, and I found some information to look at it before I could figure it out. Data Url:ASP.NET MVC's Razor Engine: View compilation principle
Simply put: A view is eventually compiled into a class, and the base class of this class can be customized as a derived class of the Webviewpage class, so you can complete the type conversion of the context in this derived class and replace it with the base class of the View page. Of course, after customizing the replacement, also remember to change the relevant configuration, let MVC use your custom view page derived class as the base class to generate the page.
(3) In addition, to speak, code reading, the division of the code is placed.
A The Brnmall.data in Brnmall's library are primarily database entity classes (dealing with various table objects), Brnmall.core are primarily the interface and policy configuration management classes used for business logic and accessibility (e.g., mail interface and configuration, order interface and configuration), Brnmall.servi Ce is the specific implementation of business logic
(B) When reading the Presentatio, it is important to read two points:
First: The framework of the custom transformation of the author is how to do, in BrnMall.Web.Framework, in the controller of the master module of the control base class is derived, mainly in the derived class to complete the page context information automatic recording. This way, when the user visits the homepage of the page, it can automatically get a lot of information, such as: browser type, whether it is mobile device users and so on. In Viewpages, the main thing was to do the automatic conversion of the type return to the acquired context. In the pager, the main page has been related to the processing. In validator, the use of logic and regular expressions of the legality check of various information is mainly encapsulated. But theme this theme style question, at present did not read deeply, later does the analysis.
Second: When we look at the code, we generally want to know the starting point of the program and the logic of the jump. We know that the MVC program has a startup project, and Brnmall.web is the startup project, which is the starting point for the program in its global.asax.
namespace brnmall.web{public class Brnmallapplication: System.Web.HttpApplication {protected void Application_Start () {//replaces the default view engine with Themerazorviewen Gine engine ViewEngines.Engines.Clear (); VIEWENGINES.ENGINES.ADD (New Themerazorviewengine ()); Register all the Zones/*arearegistration.registerallareas () is called in Global.asax, it will find all the arearegistration subclasses, * either in W EB project, or in other class library projects. So we put a arearegistration subclass in the project's API folder, * It can be found, and then, when registering the area, passing the controller's namespace in the parameters, the problem is solved. */Arearegistration.registerallareas (); Routeconfig.registerroutes (routetable.routes); Start Event mechanism Bmaevent.start (); Reset the online user form after server outage starts if (Environment.tickcount > 0 && environment.tickcount < 900000) Onlineusers.resetonlineusertable (); } }}
When started here, Brnmall made a lot of substitutions and settings, such as: View engine, routing table registration, there is an important setting: Arearegistration.registerallareas ();
What is the function of this code? It is in the same solution that different projects use different areas, regions. The jump and invocation of each project area are related to the writing of area and route. What does that mean? For example, if a user accesses brnmall with a mobile phone, how does it display the page, first in the main area, that is, the Brnmall.web controller HomeController the index method
/// <summary> ///Home Controller Class/// </summary> Public Partial classHomecontroller:basewebcontroller {/// <summary> ///Home Page/// </summary> PublicActionResult Index () {//determine if the request is from a mobile device and redirect to a mobile theme if it is if(Webhelper.getqueryint ("m") !=1&&webhelper.ismobile ())returnRedirecttoaction ("Index","Home",NewRouteValueDictionary {{" Area","Mob" } }); //the data on the home page needs to be called directly in its view file, so the view model is no longer needed here returnView (); } }
View Code
In this method, it determines whether the context is a mobile device, and if so, jumps to the index method of the controller with the same name on the area of the mobile project.
Determine if the request is from a mobile device and redirect to a mobile theme if it is
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 area and how to define area. There are two ways to define area, one is to add area to the same project, and the other is to have different area for different projects in the same solution.
And Brnmall is the second structure, in each of the non-main area, There is a file in the project with the interface view: The AreaRegistration.cs file, which defines the derived class of the Arearegistration class, which specifies the name and routing method of the area in this derived class. Finally, at the beginning of the program again by calling Arearegistration.registerallareas (); You can automatically find all the defined area and the corresponding routing method. This is another thing to be aware of. The following is also a reference to the online article.
. Net/asp.net MVC (Modular development Araeregistration)mvc-redirecttoaction jump to other area
Write this today first, next time we read Nopcommerce's starting structure analysis, a little pressure, because the sense that the code is more difficult, try your best!
If you want to make friends, you can add me qq:9200118.
(2) dotnet Open source e-commerce system-brnshop VS Nopcommerce (dotnet two sets of e-commerce to pk--the second: where the code starts-brnmall3.0beta)