The ASP.NET Core framework uses a model metadata provider to extract information from the model. This metadata provider is accessible through the MetadataProperty
of Html
, and is exposed as an IModelMetadataProvider
. By default, it is set to an instance of DefaultModelMetadataProvider,
and can be changed through the dependency injection framework.
Its contract defines only two relevant methods:
GetMetadataForType
(ModelMetadata
): Returns metadata for the model type itselfGetMetadataForProperties
(IEnumerable<ModelMetadata>
): Metadata for all of the public model properties
To change it, just call one of the registration methods of the dependency injection framework (ConfigureServices
):
services.AddSingleton<IModelMetadataProvider, CustomModelMetadataProvider>();
You never normally call these methods, they are called internally by the framework. The ModelMetadata
class they return (which may actually be of a derived class, such as DefaultModelMetadata
) is what should...