zoukankan      html  css  js  c++  java
  • 【转】ASP.NET MVC 3 Service Location, Part 7: Model Metadata

    Model Metadata

    ASP.NET MVC 2 introduced an extensible model metadata system where developers could implement a class which derived from ModelMetadataProvider to provide meta-information about the models in the system. In ASP.NET MVC 3, we have made the metadata provider findable via the dependency resolver.

    Disclaimer

    This blog post talks about ASP.NET MVC 3 Beta, which is a pre-release version. Specific technical details may change before the final release of MVC 3. This release is designed to elicit feedback on features with enough time to make meaningful changes before MVC 3 ships, so please comment on this blog post or contact me if you have comments.

    Writing a Metadata Provider

    For more information about ModelMetadata and what would be involved in writing a metadata provider, please see my blog post ASP.NET MVC 2 Templates, Part 2: ModelMetadata.

    Location: ModelMetadataProvider

    This is a “singly registered” style service introduced in MVC 2. The static registration point for this service is atModelMetdataProviders.Current for non-DI users.

    The model metadata provider inspects models, and returns meta-information about the models, include information like display names, formatting strings for display and editing, flags on whether a value is editable or not, etc.

    The logic in ModelMetadataProviders was updated to attempt to find the implementation of ModelMetadataProvider first by calling DependencyResolver.GetService(typeof(ModelMetadataProvider)). If the service does not exist in the dependency resolver, then it falls back to the static registration point. If you register a model metadata provider in both the static registration point and in the dependency resolver, MVC will throw an exception (since the service is intended to be singly registered).

    The default model metadata provider continues to be DataAnnotationsModelMetadataProvider.

    What’s Next?

    Next up in the series is Value Providers.

  • 相关阅读:
    SVN服务器搭建和使用(一)
    SVN服务器搭建和使用(一)
    lua loadstring与loadfile
    lua loadstring与loadfile
    lua_getstack
    lua_getstack
    让程序在崩溃时体面的退出之Dump文件
    bzoj1054
    poj3678
    poj2749
  • 原文地址:https://www.cnblogs.com/NickYao/p/1944816.html
Copyright © 2011-2022 走看看