title: Is it valid to replace DataAnnotationsModelMetadataProvider and manipulate the returned ModelMetadata
body: <p>We are currently building a mid-sized intranet application using MVC3. One requirement is the possibility to change and translate field names and labels on the fly. We are currently using extended versions of <code>ViewPage</code>, <code>ViewMasterPage</code> and <code>ViewUserControl</code> enriched by an translation helper injected by spring.net to achieve this requirement.</p>
  
  <p>This solution solves all requirements except MVC features that rely on <code>ModelMetadata</code> (e.g. <code>LabelFor</code>). My first thought was that there should be an extension point to replace the current implementation. Luckily the MVC team build <code>ModelMetadataProviders</code> in a way that I can inject a custom translation aware <code>DataAnnotationsModelMetadataProvider</code>.</p>
  
  <pre><code>protected override ModelMetadata CreateMetadata( IEnumerable&lt;Attribute&gt; attributes, Type containerType, Func&lt;object&gt; modelAccessor, Type modelType, string propertyName )
  {
    // Call the base method and obtain a metadata object.
    var metadata = base.CreateMetadata( attributes, containerType, modelAccessor, modelType, propertyName );
  
    if( containerType != null )
    {
      // Obtain informations to query the translator.
      var objectName = containerType.FullName;
      var displayName = metadata.GetDisplayName();
  
      // Query the translator.
      var translatedDisplayName = Translator.Translate( objectName, displayName );
  
      // Update the metadata.
      metadata.DisplayName = translatedDisplayName;
    }
  
    return metadata;
  }
  </code></pre>
  
  <p>I'm using the <code>containerType</code> and <code>GetDisplayName()</code> as key to obtain a translation from a translation contributor (that uses caching, does not degrade performance), then calling base and change the returned <code>ModelMetadata</code> by updating the <code>DisplayName</code> property before returning it.</p>
  
  <p>What makes me unconfident about this solution is that I can't predict what side effects I have to expect? Or if there is a better, proper solution?</p>