Maverick. Net Introduction

Source: Internet
Author: User
Tags xslt
Maverick. Net is the. Net version of Maverick, an open-source MVC Web framework in the Java Community. For more information, see the project homepage. Regardless of whether Maverick. Net is good or not, it is a good idea to understand it. The following is a brief introduction to Maverick. Net as a whole, in order to be able to understand some related concepts of Maverick. Net from a global perspective and how to work. In addition, I have not used Maverick. net has developed a project, but has some ideas after reading its architecture and source code. I want to share it with you and want to know about Maverick. net. 1. Main frameworkTypical process of Maverick. Net Processing HttpRequest is shown in Figure 1: Processing request Reference: MaverickLite Specification Maverick. Net ing each HttpRequest to Command. It is easy to see that the submitter of Command is the user interface, that is, View. The processor should be the Controller of the business logic, that is, the Controller. In this way, when Maverick. Net Framework processes every Command, it mainly solves the following problem: how to generate a Model from parameters submitted on the user interface (View? Which Controller is used to process specific commands and how to pass the Model to this Controller? After the Controller finishes processing, how does one present the processing result to the user (for Maverick. net is based on the Controller processing results, select which View to return to the User Interface) and how to pass the Model to the returned result View? Maverick. Net is configured through a configuration file. The typical Command configuration node is as follows: This is a Command configuration node submitted for user registration in the Friendbook of the Maverick. Net project example. After receiving the HttpRequest for submission and registration, the Dispatcher obtains the Command Name of signupSubmit to obtain this Command object. Command creates the specified Controller object Friendbook. Ctl. SignupSubmit. Friendbook and calls the Controller for processing. The Controller processing result should be a successful registration, and you need to switch to the View after the registration is successful; or an error occurs, you need to switch to the View where the registration information is re-filled. Maverick. Net Framework specifies that the returned result of the Controller must be a View name. In this way, after the Command calls the Controller for processing, it will know which View object to render. If the registration is successful (success), the View of name = "success" will be called; if the registration fails, for example, the two passwords are inconsistent, the View with name = "error" is called. The View type of name = "success" is redirect. The current MaverickContext object (including HttpContext and Model aggregated) is redirected to another object named edit. m Command object (View type and so on); name = "error" View type is document (default type, no need to write type = "document "), the Server will be used directly. execute () method to get the HTML output of the View, and use the Transform object to convert the HTML output of the user registration result View into the HTML code of the overall page, and return it to the client (the concept of Transform, later ). 2. Main classes and objectsThe main classes or objects of Maverick. Net are as follows: Dispatcher, Command, Controller, View, Transform, and MaverickContext. 2.1 DispatcherDispatcher is an HttpHandler class used to intercept and process HttpRequest. The ing of HttpRequest-Command is completed by Dispatcher. In typical cases, Maverick. Net uses the. m suffix as an ISAPI extension and maps it to Command. In this case, all HttpRequest files submitted by the browser end with the. m Virtual File Name and are submitted to the Dispatcher. This file does not exist on the server. After the Dispatcher receives a request similar to login. m, it removes the. m suffix, takes login as the Command Name, obtains the Command object, and processes the request. Maverick. the old version of Net is basically copying the Java version of Maverick. At the View level, it only supports Servlet writing like JSP, that is, purely ASP, or aspx pages written in ASP mode. ViewState, Postback event mechanism, and user control cannot be used in ASP. Net environment, which is a huge loss for ASP. Net environment. Starting with version 1.2, Maverick. net Controller fully supports server-side controls and user controls of aspx, so that Maverick can be used. net Framework, and based on ASP.. Net. When the aspx Controller is used, the Interception Function of Dispatcher is removed, but ASP is used. net default HttpHandler, the page class inherits Maverick. ctl. aspx. controllablePage: In the Render method of the page, ControllablePage refers to Maverick.. Net Framework. In this case, the Command Name is no longer a. m suffix, but directly becomes the corresponding aspx page name, for example, <command Name = "Default. aspx">. In addition, the Dispatcher is responsible for constructing the MaverickContext object when processing the request, so that the Command, Controller, View, and Transform can obtain the corresponding context information during their respective processing. 2.2 CommandCommand is similar to a commander. It creates a Controller object based on the configuration in the Maverick. config file and calls the Controller for processing. Based on the returned results of the Controller, select the corresponding View object and execute it. The Command can have no Controller. In this case, the request to the Command actually presents the specific View to the client. In Maverick. Net, this is CommandSingleView. In addition, you can inherit the ICommand interface to implement some special functions or custom commands. For example, the Maverick. Net Framework itself implements two special commands: ReloadCommand and CurrentConfigCommand. CurrentConfigCommand is used to view the content of the current configuration file. This Command reads the content of the Maverick. config configuration file and directly outputs the xml in the configuration file. In addition, Maverick. net will read Maverick when processing the request for the first time. in config, create and cache the Command, View, and Transform objects according to the configuration. Subsequent requests only retrieve the corresponding objects from the cache. If these configurations are updated after the first access, these updates are not immediately reflected in the cached object. ReloadCommand is used to recreate the cached object based on the content of the current Maverick. config configuration file. 2.3 ControllerThe Controller is responsible for processing the business logic. In a typical application, Controller first obtains the parameters submitted from the user interface (View) through the HttpContext object in MaverickContext, creates a Model object, and uses the Model to process the business logic of the request. Different processing results of the Controller are used to determine which View to select. The Model may be updated during the processing of the Controller, or some parameters need to be passed to the View, which will be completed through the context object MaverickContext. In aspx Controller, because the Interception Function of Dispatcher is discarded, the creation of MaverickContext object is also completed in Controller. 2.4 ViewIn the concept of MVC, View is responsible for presenting certain slices of a specific Model or the entire Business Domain Model to the client. In Maverick. Net, View is divided into multiple types. DocumentView: This is the default View type. This type of View will configure a file, such as asp, aspx, or html. Call Server. Execute () to obtain HTML output and send it to the client. ForwardView: This type of View uses the current MaverickContext to redirect to another Command for execution. If structs-based system analysis is designed, a business operation may be divided into multiple commands/actions, and these commands/actions are combined to form a new Command/Action, or it corresponds to a business operation. The forward type View is used to support this form. RedirectView: This type of View will be directly redirected using the Response. Redirect () method. Therefore, the View of the forward type can also be considered as a special case of the redirect type. In fact, there are quite a few examples of Maverick. Net projects. This is because the Dispatcher intercepts HttpRequest. After a statement like Response. Redirect ("edit. m") is executed, it will still be blocked by the Dispatcher and start executing a new Command. TrivialView: for this type of View, Maverick. Net outputs the Model object of MaverickContext directly (extracts the content and outputs it directly ). This requires that the Model object of MaverickContext be of the following types: String, System. Text. StringBuilder, System. IO. TextReader, and Sytem. Xml. XmlNode. XmlSerializingView: This type of View is output after the Model of MaverickContext is serialized into xml format. This View is mainly used for xml-based website solutions or for the purpose of providing system interfaces. 2.5 TransformIn the View of Maverick. Net, the View execution result is not the final output presented to the client, and must be converted through Transform. Transform implemented by Maverick. Net includes DocumentTransform and effecttransform. It is easier to understand the Transform concept of Maverick. Net from the XsltTransform type. For XsltTransform, View is an xml or XmlSerializing type View. To convert this xml to HTML output, you need to use the xsl/xslt file for conversion, which is the work of XsltTransform. For DocumentTransform, the word Transform is far-fetched. First, DocumentTransform is a View for asp, aspx, html, and other document types. In our image, Maverick. Net uses the Server. Execute () method for this type of View. In this way, the HTML code has been directly obtained. Why should we go through a DocumentTransform process? In fact, for a system, the work page is divided into different areas, such as the Banner area of the page, menu/function list area, and general toolbar. Different controllers are responsible for processing these different regions, and the corresponding models are also different. In Command processing, a specific Command only uses its own Controller object to process the corresponding Model. Therefore, it should only be responsible for the display of the area under its jurisdiction on the page. In this way, the result of View execution is only an update of the region under Command, not the whole page. As for how to display updates in this area throughout the page, this is the work of DocumentTransform. Currently, Maverick. Net processes DocumentTransform in the following way. For example, a View of the document type corresponds to An aspx file. View uses the Server. Execute () method during execution to obtain the output HTML code. However, this is not the complete output to the client, but only part of it. Maverick. Net saves this HTML clip in HttpContext. Items. The DocumentTransform object corresponds to An aspx page, which should complete the overall layout of the system page, and. in Items [""], extract the HTML after the View is executed and output it in the appropriate position. In this way, after the Server. Execute () method is used to call the aspx page of DocumentTransform, It is the complete HTML sent to the client. In fact, Transform considers the overall layout of the page. A View is only responsible for a specific area, but it does not support complicated layout. It can only be said to be lightweight. Complex la s are implemented through iFrame or some other implementations, or some modifications are made and then partially updated in combination with Ajax. 2.6 MaverickContextThis is a context object that transmits information between commands, controllers, and views. It contains HttpContext, Model, and an IDictionary type Params attribute. The HttpContext object is provided by the creator (Dispatcher or ControllablePage) When MaverickContext is created. The Model is created when the Controller executes the processing. Params is used to pass other parameters as needed. From the MVC perspective, the processing process is as follows: 3. Summary In other articles about Maverick. Net, I have seen many discussions about Maverick. Net and ASP. Net on how to use MVC. In fact, the use of development and Architecture Design Under. Net is a matter of benevolence and wisdom. It just depends on how we use it. The following thoughts are just about the architecture model of enterprise-level applications. Of course, it is a different theory for small projects based on rapid development. 3.1 M-V-C SeparationASP. Net itself is indeed a MVC framework. It can be said that it is a very powerful and useful MVC framework, but there are some obstacles blocking us. Many features of ASP. Net make the concepts between M-V-C fuzzy or even confusing. Let's take a look at this scenario: Add a Web Form, add databases like GridView and Connection to Form in the Drag-Drop mode, and set the corresponding attributes, such as database Connection, the data source binding of the GridView. It may be as simple as 1 or 2 lines of code or even 1 line. Running this Web Form will display the data. Everything is so convenient and simple that it brings a revolutionary idea to BS development. However, based on the enterprise-level application architecture, what can you get and think of in such a scenario? Of course, for experienced people, this is not a problem at all. By writing a piece of code, you can reflect the idea of MVC. It doesn't matter which language or tool you use. What happens if hundreds of developers need to work together to complete a project? ASP. Net itself is not too binding on the architecture, although it is a good MVC framework. In this case, it is very important to constrain and standardize the collaborative developers in the architecture. Otherwise, how to ensure development according to the architecture and design scheme is disastrous. Maverick. Net is very clear in the presentation of MVC. You may find that such an idea needs to be introduced in your architecture. No matter which sub-team or who uses this framework, you need to understand its ideas and develop it according to its specifications. 3.2 transformation of Analytical Design Ideas MDAFrom a large perspective, the boundary between user requirements and software systems is what is at the UI presentation layer, that is, View. In the end, a system presents all its contents to users through views or interfaces to other systems. System development is the implementation of requirements, while architecture design is the abstraction of requirements. In small projects, no methodology is required. After grasping the requirements, we will focus on the design of the presentation layer. After confirming with the user, we will be able to develop the system with this goal. This is a direct method and a method that is easy to accept in human thinking models. In the architecture of enterprise-level applications, if we drive in this way to varying degrees and take the presentation layer as the main body more or less, it will impede our abstract behavior, that is, it will affect the quality of the architecture. In the idea of MDA, it is emphasized that the Business Model is extracted from the demand first, and then the Model is used as the main body to analyze the Business logic. At the framework level, the M-V-C is clearly distinguished, which is conducive to the transformation to the MDA mode in the aspect of analysis and design ideas. 3.3 simple and powerful frameworkI forgot where I saw this sentence. It is simple, because the entire Maverick. net project code is very few, the main object used for implementation is not much, it only uses a framework protocol to separate M-V-C, model, View, and Controller are not extended or processed too much. All aspects of View presentation and Controller architecture are completely determined by the user. It is powerful because the overall framework is quite scalable. But it doesn't mean that such a good framework can be used. Speaking of it is good, probably in terms of its ideological level, does not mean that its current implementation is the best or very reasonable. List the following items: A) There are multilingual solutions, but they are not implemented. B) How can I use the class-based Controller configuration? Solution 1: Use its Controller as Business Facade. Therefore, you may need to write a Controller class for each Command to integrate the various Business Rule classes corresponding to the Business Model. This solution is conducive to the application of distributed and SOA, but it is a little complicated to develop a Controller for each Command. Solution 2: Uses Controller as the complete Business Logic encapsulation. Uses parameters and other mechanisms in the context to associate Command with the Controller method. C) Select the Controller + View type Solution 1: Use aspx Controller. The advantage of this method is that ASP can be used. net mechanism, including the general PostBack event mechanism, user control, or integration of ASP.. Net and other things, such as Atlas, may be more convenient. However, in my opinion, we do not advocate *. aspx. cs as the Controller, but purely as part of the View. *. Aspx. cs is only responsible for using ASP. net mechanism, GET parameters from the page, create a Model object to pass to the control class; after re-obtaining Model and other related information from the control class (the result of the Controller processing), and then use ASP. net mechanism. Of course, you can also consider using *. aspx. cs as a lightweight Business Facade. Solution 2: Use the xml or Maverick. Net standard document method. In fact, there is a big difference between the two methods. In xml format, XsltTransform is used for conversion, and a large number of xslt files may need to be written. The use of the Maverick. Net standard document method refers to a method similar to ASP, using DocumentTransform for conversion. Both methods use a typical working method of Maverick. Net, that is, using. m as the suffix of the Request page, and the Dispatcher processes HttpRequest. When writing pages, neither of them can use ASP. Net. In this way, the ASP. Net mechanism is completely abandoned. Therefore, it is not surprising that ASP. Net developers regard them as the same method. Using this method for development may not be acceptable to many people. However, this method makes some effort in View development, such as encapsulation, extension of generic templates, and addition of Maverick. to some extent, the Ajax solution of Net can reduce the complexity of View development in this way, to a level that is basically acceptable (compared with ASP. net developers ).

: Add a picture

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.