. NET/ASP. NETMVC Model metadata, HtmlHelper, user-defined templates, and template-based modifier mode (1)

Source: Internet
Author: User

Reading directory:

  • 1. Introduction

  • 2. Relationship between Model and View data context DataContext and View presentation)

  • 3. Metadata-driven design how to use intermediate layer Metadata to drive final behavior)

  • 4. How does ASP. NETMVC ModelMetadataModelMetadata metadata support the composite relationship between Model and View)

1. Introduction

In this article, let's take a look atMode metadataRelated designs and some other object models around metadata, how they coordinate with each other to support a flexible interface programming interface;

Actually, metadata is mentioned.Metadata) You have seen an application framework more or less before, but it may not attract your attention. In fact, we can see the shadows of Matedata in many application frameworks, it is a very good framework design model, commonly known:"Metadata-driven design"It is very similar to many current design ideas, such:Metaprogramming,Contractual DesignThese modes aim to control coupling well and generate great scalability. Meta programming allows us to dynamically generate code for running software based on the final user selection, the contractual design allows us to set control far away, so as to control the scalability at a large granularity and set rules according to the contract, the control end then dynamically generates the final required rules at runtime;

Through in-depth understanding of these models, we can basically extract two golden rules for design: 1. migrate the change point from compilation to runtime; 2. migrate the change point from hard encoding to configuration;

This is just a simple introduction. every topic will be very detailed and will contain many domain concepts, terms, and important design ideas in this direction. Therefore, this is just a brief introduction, this article will focus on"Metadata-driven design"Programming ideas and where it is, and then in ASP. what role does NETMVC play? How does NETMVC build a high-speed bridge between Model and View, so that the matching relationship between Model and View can be 1-to-N, in large websites, viewmodels are usually fixed, but there may be thousands of views. How to achieve this high degree of adaptation is the function of custom templates. Of course, everything is built onModelMetadataBasis;

2) Relationship between Model and View: data context: DataContext and View presentation)

In the definition of MVC, the Model is accurate to ViewModel instead of DomainModel. ViewModel is short for display Model, and the data to be displayed is integrated into a DataContext, it is derived from the Query data source in the enterprise application architecture. In general, such a ViewModel will not change frequently and is a Common data context abstracted based on a large number of business scenarios;

In website-based systems, especially e-commerce platforms, interface changes are common, and some display methods on the interface may be changed almost every day, the presentation of the same set of data on the UI may be different. Here, a combination of Model and multiple views will be formed, and a Promotion will be performed.) data context, different UI components are generated by different views;

Figure 1:

650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/123R05592-0.jpg "title =" 1.jpg" width = "700" height = "304" border = "1" hspace = "0" vspace = "0" style = "width: 700px; height: 304px; "alt =" 133844642.jpg"/>

It can be concluded that a data context object may be used by many views in most cases, so ASP. NETMVC requires strong customization. A Model can present multiple UIS at will without messing up the ViewModel;

Note: A ViewModel may have a large data entity. It is best to cut the ViewModel to cope with different display scenarios and pull out the inheritance system, instead of coupling all viewmodels to a large ViewModel, in this way, each query will involve some irrelevant attributes;

3. Metadata-driven design how to use intermediate layer Metadata to drive final behavior)

Metadata-driven design modelIt is one of the many classic framework design modesContractual DesignIn fact, the essence of framework design is how to flexibly use some framework design patterns. Different Languages and platforms use different models, however, the central idea of the model remains unchanged. No matter how you design it, the essence of the framework model must be presented;

Among the numerous Frame Design PatternsSuch as contractual design, metaprogramming, metadata-driven design, pipeline model, remote proxy model, and provider model;The metadata-driven design mode is frequently used, and is easy to use because of its low complexity. In fact, in many existing. NET frameworks, such:WCF, ASP. NET, Remoting, WinformYou will see the shadows of Metadata, but you do not have to add them when naming them.MetadataAnd will be used in many cases.DescriptionTo replace;

Metadata is usually used to support data. It is the data that describes the data and is actually parsed. Since it is the data that describes the data, there is a description in that direction, what is the description angle and the description level;

Let's take ModelMetadata as an example. In ASP. in NETMVC, the usage direction of the Model is basically limited to three operation sets. First, the requested data binding, second, the verification during data binding, and third, the final presentation of the Model; modelMetadata should contain all the data required by these three operation sets. Of course, it can also be divided into three sets of metadata object models and included through the inheritance system; modelMetadata needs to describe the required data set in three directions. The Model itself is a medium data, and uses ModelMetadata to abstract and describe the data at the second level, data used in three operation sets is included, that is, three angles and two layers. If your framework needs to have multiple layers, you need to further refine the abstraction;

Figure 2:

650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/123R01S2-1.jpg "title =" 2.jpg" width = "700" height = "252" border = "1" hspace = "0" vspace = "0" style = "width: 700px; height: 252px; "alt =" 133914328.jpg"/>

Standard Data is converted into Meta data through an intermediate link and then handed to the final processing program for use. You can clearly understand the core role of metadata, it can well decouple the processing program from the standard data, so that the intermediate metadata can provide more flexibility. Through this middle layer metadata, we can easily configure the metadata;

We assume that there is no intermediate layer metadata. No matter how designed, the operating program will be coupled with standard data entities, and the purity of standard data should be ensured, it is impossible to always use inheritance, characteristics, and other heavily polluted intrusions to ensure fullPOCOPlain Old Csharp Objects)It is difficult to extract the data that can be used at runtime without the support of IDE during compilation; at this time, if we need to modify the type of the standard metadata or modify the logic of the operating program, the two will be more or less affected;

If metadata is used, we can migrate the definition part of table data to the configuration file, and then expand the source of reading metadata in the metadata provider, standard data can be stored on any cloud platform or even far away. For the operating program, we can extract the interface for obtaining metadata into a Service method and read metadata from any place;

You may decide that you will never use these solutions, but who can use all the functions of a framework? Different system requirements may require these extensions;

4. How does ASP. NETMVC ModelMetadataModelMetadata metadata support the composite relationship between Model and View)

To be continued, stay tuned ......


Author:Wang qingpei

Source:Http://wangqingpei557.blog.51cto.com/

The copyright of this article is shared by the author and BKJIA. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide the original article connection clearly on the article page. Otherwise, you will be entitled to pursue legal liability.


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.