title: How to remove dependency on System.Web.Mvc within domain model assembly containing POCOs
body: <p>I have an assembly generated using POCO template using Entity Framework (e.g. "Company.Models.dll").Besides generated POCOs I also have "follow up" partial classes that define meta data using <em>System.ComponentModel.DataAnnotations</em>.
  So for example Company.Models.Customer is auto-generated (in separate folder) and then I have partial class with same namespace. Within this partial class I define inner class for metadata...For example:</p>
  
  <pre><code>using System.ComponentModel;
  using System.ComponentModel.DataAnnotations;
  
  namespace Company.Models
  {
      [MetadataType(typeof (CustomerMetaData))]
      public partial class Customer
      {
          public override string ToString()
          {
              return String.Format("Id: {0}, Name: {1}", Id, Name);
          }
  
          //[Bind(Exclude = "Id")]
          public class CustomerMetaData
          {
              [ScaffoldColumn(false)]
              public int Id { get; set; }
  
              [DisplayName("Name")]
              [Required(ErrorMessage = "Customer Name is required.")]
              [StringLength(100, ErrorMessage = "Customer name cannot exceed 100 characters.", MinimumLength = 2)]
              public string Name { get; set; }
          }
      }
  }
  </code></pre>
  
  <p>The issue I am having is that I now want to use this assembly in my MVC project and want to use MVC specific attributes (like the commented out Bind attribute above).However, doing so requires making my Company.Models.dll dependent on System.Web.Mvc.dll.</p>
  
  <h2>I would like to avoid this at all costs if possible but how?</h2>
  
  <p>So far I am aware of 2 possible solutions and am asking community for their opinions or better approaches...</p>
  
  <h2>Solution 1</h2>
  
  <p>This solution has been discussed here: <a href="https://stackoverflow.com/questions/2790736/using-data-annotations-on-pocos-with-mvc-for-remote-validation">Using Data Annotations on POCO&#39;s with MVC for Remote Validation</a> The "trick" was to use ViewModels and map (either mannually or using AutoMapper) POCOs to MVC project specific ViewModels. Then apply all necessary attributes to ViewModels instead of domain model POCOs. While this makes sense for large projects it is a bit overkill for small simple solutions...</p>
  
  <h2>Solution 2</h2>
  
  <p>Use Bind attribute in Controller action parameters (as seen on some <a href="http://www.asp.net/mvc" rel="nofollow noreferrer">http://www.asp.net/mvc</a> tutorials). For example:</p>
  
  <pre><code>//
  // POST: /Customer/Create
  [AcceptVerbs(HttpVerbs.Post)]
  public ActionResult Create([Bind(Exclude="Id")]Customer customerToCreate)
  {
          if (!ModelState.IsValid)
          return View();
  
          // TODO: Add insert logic here
      return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>Using this solution would allow to skip dependency on System.Web.Mvc from my POCO dll at the cost of having to remember to insert Bind attribute on all relevant Controller actions.
  Also, if I have multiple ASP.NET MVC projects the issue gets worse...</p>
  
  <p><strong>So, is there another way? ;)</strong> </p>