title: Entity Framework 5 code-first configuration encapsulation
body: <p>I was wondering (and I hate using the words 'Best Practice') - but is this a good way to approach configuration as it encapsulates the config for AAA?</p>
  
  <p>I see a lot of examples where the <code>OnModelCreating</code> is a huge list of instructions for creating the database and long methods tell me something isn't quiet right.</p>
  
  <pre><code>public class MyContext : DbContext
  {
      public MyContext() : base("name=MyDb") { }
  
      public DbSet&lt;AAA&gt; AAAs { get; set; }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();
          modelBuilder.Configurations.Add(new AAA.Configuration());
      }
  }
  </code></pre>
  
  <p>And the class with a spot for it's config</p>
  
  <pre><code>public class AAA
  {
      [Key] 
      public int Id { get; set; }
  
      [Required] 
      public string Details { get; set; }
  
      internal class Configuration : EntityTypeConfiguration&lt;AAA&gt;
      {
          public Configuration()
          {
              // Set all the funky stuff here
          }
      }
  }
  </code></pre>
  
  <p>I get that there probably isn't <strong><em>one right way</em></strong>. Before I commit a lot of time and tears I am looking for a reason why this might be absolutely the worst idea in the world or if there is a way to do something similar?</p>
  
  <p><em><strong>EDIT</em></strong></p>
  
  <p>A Colleague suggested this as an alternate method using a static property </p>
  
  <pre><code>public class AAA
  {
      [Key] 
      public int Id { get; set; }
  
      [Required] 
      public string Details { get; set; }
  
      public static EntityTypeConfiguration&lt;AAA&gt; Configuration
      {
          get { return new AAAConfiguration(); }
      }
  
  }
  
  internal class AAAConfiguration : EntityTypeConfiguration&lt;AAA&gt;
  {
     public AAAConfiguration()
     {
              // Set all the funky stuff here
     }
  }
  </code></pre>
  
  <p>I like this as it gives me a bit more flexibility with how the configuration is instanced. </p>