title: Autofac: How to use construction injection on class with dependency to another object function output
body: <p>This question is about IoC in general, but I'm using Autofac, so an Autofac solution would be great.</p>
  
  <p>So assume the following classes:</p>
  
  <pre><code>class A
  {
      IEnumerable&lt;B&gt; GetBs();
  }
  
  class B 
  {
      // Some code
  }
  
  class C
  {
      readonly IEnumerable&lt;B&gt; bs;
  
      C(IEnumerable&lt;B&gt; bs)
      {
          this.bs = bs;
      }
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          var builder = new ContainerBuilder();
          builder.Register&lt;A&gt;();
          builder.Register&lt;C&gt;();
  
          var container = builder.Build();
          var c = container.Resolve&lt;C&gt;();
          // do something with c
      }
  }
  </code></pre>
  
  <p>the above <code>Main</code> will fail.</p>
  
  <p>I've noticed that I can solve this by adding this line of code:</p>
  
  <pre><code>builder.Register(c =&gt; c.Resolve&lt;A&gt;().GetBs())
  </code></pre>
  
  <p>However, that doesn't feel right. Any other way to achieve this? Or design changes?</p>