title: Is there a way to instruct ASP.NET MVC about some class metadata other than putting the MetadataTypeAttribute directly on the class?
body: <p>Here's a sample of how it works now:</p>
  
  <pre><code>[MetadataType(typeof(PersonMetadata))]
  public class Person
  {
      public string Name { get; set; }
      public int Age { get; set; }
  }
  
  public class PersonMetadata
  {
      [Required]
      public string Name { get; set; }
      [Range(0,150]
      public int Age { get; set; }
  }
  </code></pre>
  
  <p>However I don't want the MetadataAttribute to be put on the Person class, instead I want some way of telling the MVC framework "hey if you encounter Person class the metadate is in the PersonMetadata class".  </p>
  
  <p>It's just reversing the direction which for me feels more compositional and following the Open-Close Principle since I don't have to touch the Person class to "extend" it with metadata.<br>
  I know this creates a problem of possible multiple and conflicting metadatas being attached, also increases complexity but flexibility always comes at a price.</p>
  
  <p>I want either a programmatic or declarative way or preferably both :)</p>
  
  <p>So one could be something like :</p>
  
  <pre><code>MetadataTypeMappings.Add(typeof(Person), typeof(PersonMetadata));
  </code></pre>
  
  <p>Another could be:</p>
  
  <pre><code>[MetadataFor(typeof(Person)]
  public class PersonMetadata
  {
      [Required]
      public string Name { get; set; }
      [Range(0,150]
      public int Age { get; set; }
  }
  </code></pre>