Summary of the model metadata provision mechanism

Source: Internet
Author: User

  At the very beginning, I have to talk about this part of the situation. At the beginning, I was dizzy by various modelmetadata and various modelmetadataprovider. It took me a lot of time to read several pages, after looking at a class chart, I will take a closer look at the relationships between classes and read this part again. I have learned something about it. This is probably a way to read books in the future, look at the code method and first understand the structure so that it will not be confused by a large class library. Then I first listed the class chart, which was adjusted based on my personal preferences.

 

The left side of the entire graph is the modelmetadata part, and the right side is the provider of metadata. Although many attributes of metadata are described earlier in this chapter, the metadata used in MVC is not modelmetadata, it is a subclass of the class. Next we will introduce the classes one by one. The introduction is divided into two parts: the model metadata on the left and the metadata model provider on the right.

Model metadata
  • Dataannotationsmodelmetadata: MVC uses declarative definitions based on Annotation features, so this class is defined. Displaycolumnattriute is used in the constructor of this class, which is mainly related to display. This attrubute class is used, and its label value is the value of the corresponding attribute of this class, for example, the address in the book is displayed with the displaytext attribute value of address.
  • Cachedmodelmetadata <tprototypecache>: Built in prototype mode or provided by the provider of the subclass cacheddataannotationsmodelmetadata to calculate the attributes of all model metadata. Its examples are also prompted in the book.
  • Cacheddataannotationsmodelmetadata: Default metadata type in MVC, inherited from cachedmodelmetadata <cacheddataannotationsmetadataattribute>, used to cache the model metadata information type. This attribute contains all model Metadata Annotation features.
Model metadata provider
  • Modelmetadataprovider: Abstract base class of all providers, which defines the get method for obtaining metadata of several metadata.
  • Associatedmetadataprovider: Override three methods of the modelmetadataprovider base class. Actually, the abstract method createmetadata of this class declaration is called internally. This class is inherited by two providers. One is dataannotationsmodelmetadataprovider, the second is cachedassociatedmetadataprovider <tmodelmetadata>.
  • Dataannotationsmodelmetadataprovider: Inherits associatedmetadataprovider and defines the constructor of this class. Therefore, this is a actually usable provder, which overrides the createmetadata abstract method defined in ociatedmetadataprovider. To provide the corresponding metadata.
  • Cachedassociatedmetadataprovider <tmodelmetadata>: Inherits the abstract class of associatedmetadataprovider. tmodelmetadata integrates modelmetadata. It also overwrites the createmetadata of the parent class and returns the abstract method of the corresponding model metadata object. The cache function is available. If cache is available, model metadata is generated in singleton mode. If no cache is available, a new metadata is generated.
  • Cacheddataannotationsmodelmetadataprovider: Inherits cachedassociatedmetadataprovider <tmodelmetadata> and implements all the preceding abstract methods.
  • Modelmetadataproviders: Get the currently used provider through current, which is of the modelmetadataprovider type. The default value is the cacheddataannotationsmodelmetadataprovider type.

The book sees this chapter to know that the default model metadata type used in the framework is not the base class modelmetadata, but its subclass, however, many attributes related to model metadata customization are defined in the base class. I recall that the controller only controls the model in the MVC mode, the entity types used for data storage are not mentioned in the entire model. All data and business logic processing are attributed to the model, the model includes the attributes (field or prototype) and behavior (method) of the model ). The structure of these classes using model metadata solves this problem. The data part is defined as the base class, and the behavior part is placed in the subclass. This reduces the confusion between data and behavior, and facilitates data reference.

Summary of the model metadata provision mechanism

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.