title: Automatically register interface to class in autofac
body: <p>Project I'm working on, each class has its own interface with the following naming conventions</p>
  
  <p>ClassA.cs : IClassA.cs</p>
  
  <p>ClassB.cs : IClassB.cs
  etc</p>
  
  <p>Currently in the bootstrapper for Autofac I am repeatedly putting</p>
  
  <pre><code>builder.RegisterType&lt;ClassA&gt;.As&lt;IClassA&gt;();
  builder.RegisterType&lt;ClassB&gt;.As&lt;IClassB&gt;();
  </code></pre>
  
  <p>With a few singletons thrown around for good measure.</p>
  
  <p>Is there any way to automate the binding process?  i know it's not a huge amount of extra effort adding the bindings manually, but it'll get worse as time goes on I'm sure.</p>
  
  <p>I've currently got the following in my container</p>
  
  <pre><code>builder.RegisterType&lt;MyClass&gt;().As&lt;IMyClass&gt;().SingleInstance();
  
  var myAss = Assembly.GetExecutingAssembly();
  builder.RegisterAssemblyTypes(myAss)
     .Where(t =&gt; t.IsClass )
     .As(t =&gt; t.GetInterfaces().Single(i =&gt; 
     ( i.Name.Length == t.Name.Length + 1 ) &amp;&amp; 
     ( i.Name == "I" + t.Name)));
  </code></pre>
  
  <p>However looking at the watch window for builder.  It looks as though it may be registering Myclass twice.  Now I may be completely wrong here as I cannot for the life of me find what's actually being registered in builder by the watch window.  </p>
  
  <p>If I am wrong please just give me a slap.</p>