Experience ASPnet MVC preview5 (1)-explore the principle of viewengine and compare the differences between old and new versions

Source: Internet
Author: User

Asp. net MVC has finally come to the new version, this time is still the preview version. many new features are added to this version. especially in viewengine management. the improvements not only allow users to conveniently change viewengine, but also allow users to use multiple viewengines in a system, this article will explore and compare the working methods of viewengine in the new and old versions, and then demonstrate how to add one or more viewengines and allow them to interact with each other.

First, describeP5PairViewengineImprovement,In old versions,System InvolvedViewengineTwo interfaces are managed.,They are:Iviewengine,Iviewlocator,Ivewengine is responsible for rendering the view, and iviewlocator is responsible for processing the view path. at the same time, select viewengine in the Controller so that the viewengine is passed to viewresult during execution, and then the viewresult uses viewengine to render the UI. the general class diagram of the view section of the old version is as follows:

 

The execution process is roughly as follows: the MVC Framework finds the corresponding controller based on the routing data, and the Controller initializes a viewengine Based on iviewlocate (iviewlocater is generally used for Path Selection) then execute the execute method of the controller. This method indirectly uses controlleractioninvoker to execute the action. Each action returns an actionresult object and then executes the executeresult method of the actionresult. the system has many kinds of actionresult. When this actionresult is viewresult, the Controller will pass your viewresult to its own viewengine, and then use viewengine to present data in viewresult.

However, in P5, this system has been greatly improved, and many more parts have been added, making expansion and management more convenient. Of course, correspondingly, the complexity of the system has also increased. the viewengine class diagram in P5 is roughly as follows:

The execution process of this system is roughly as follows: the MVC Framework finds the corresponding controller based on the data in routing (the Controller implements the icontroller interface and no longer manages viewengine ), A controller contains an iactioninvoker object (using the previously called controlleractioninvoker interface). The execute method in the Controller indirectly executes the invokeaction method of iactioninvoker. The default actioninvoker will indirectly execute the action in this method, each action returns an actionresult. In P5, the system comes with two types of actionresults related to viewengine: Partialviewresult And viewresult. Their Inheritance relationships can be shown in the figure below. Then viewresult calls the iviewengine's Findpartialview Or Findview Method to obtain the corresponding Viewengineresult, Last call Viewengineresult In Iview Of Render Method to present View. In addition , There is another Viewengines Class to manage all Viewengine, You can Viewengies Add or delete your own Viewengine. It may be strange to say that , In this execution process . Nothing to mention Viewengine Selection Problems , If the system has multiple Viewengine, How does the system find the correct one? Viewengine And execute it. ? Actually , This is only what the system will look Viewengine To a special Viewengine To complete , This is Compositeviewengine , It is Viewengines. defaultengine This special Viewengine There is Icollection <Iviewengine> Object , This object is actually Viewengines In Viewenginecollection Is the same object , Its Findpartialview And Findview The method is Viewengine Search Method , In each Partialviewresult By default, this Compositeviewengine Object . This way , Use this Viewengine When presenting data, it will indirectly find all Viewengine, In this way Viewengine Hybrid use . It is also worth mentioning that , In Compositeviewengine Medium , System Viewname And Mastername The first found Viewengine, Therefore , When you have multiple Viewengine Pay attention to the order of addition. .

In this article, we explore the working modes of viewengine and the work differences between the new and old versions. The next article will discuss how to customize viewengine and interact with multiple viewengines.
Address: http://www.cnblogs.com/leven/archive/2008/08/30/1280097.html

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.