title: Autofac composite pattern
body: <p>I noticed I quite often need to implement composite pattern. For example:</p>
  
  <pre><code>interface IService { ... }
  class Service1 : IService { ... }
  class Service2 : IService { ... }
  class CompositeService : IService
  {
      public CompositeService(IEnumerable&lt;IService&gt; services) { ... }
      ...
  }
  </code></pre>
  
  <p>I want to register CompositeService as IService in container and have dependencies injected.</p>
  
  <p>(looks somewhat similar to Decorator but decorating set of services instead of only one)</p>
  
  <p>What's the best way to do it in autofac?</p>
  
  <p>How would ideal solution look like (for C#)?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>My current registration is:</p>
  
  <pre><code>builder.RegisterType&lt;Service1&gt;().Named&lt;IService&gt;("impl");
  builder.RegisterType&lt;Service2&gt;().Named&lt;IService&gt;("impl");
  
  builder.Register(c =&gt; new CompositeService(c.Resolve&lt;IEnumerable&lt;IService&gt;&gt;("impl")))
      .As&lt;IService&gt;();
  </code></pre>
  
  <p>It is similar to <em>Decorators by Hand</em> in <a href="http://nblumhardt.com/2011/01/decorator-support-in-autofac-2-4" rel="noreferrer">http://nblumhardt.com/2011/01/decorator-support-in-autofac-2-4</a></p>
  
  <p>Can it be improved?</p>