title: Castle Windsor: Reuse resolved component in OnCreate, UsingFactoryMethod or DynamicParameters
body: <p>I'm trying to execute an action on a resolved component before it is returned as a dependency to the application.</p>
  
  <p>For example, with this graph:</p>
  
  <pre><code>public class Foo : IFoo { }
  
  public class Bar {
    IFoo _foo;
    IBaz _baz;
    public Bar(IFoo foo, IBaz baz) {
      _foo = foo;
      _baz = baz;
    }
  }
  </code></pre>
  
  <p>When I create an instance of IFoo, I want the container to instantiate Bar and pass the already-resolved IFoo to it, along with any other dependencies it requires. So when I call:</p>
  
  <pre><code>var foo = container.Resolve&lt;IFoo&gt;();
  </code></pre>
  
  <p>The container should automatically call:</p>
  
  <pre><code>container.Resolve&lt;Bar&gt;(); // should pass foo and instantiate IBaz
  </code></pre>
  
  <p>I've tried using OnCreate, DynamicParameters and UsingFactoryMethod, but the problem they all share is that they don't hold an explicit reference to the component:
  DynamicParameters is called before IFoo is instantiated.
  OnCreate is called after, but the delegate doesn't pass the instance.
  UsingFactoryMethod doesn't help because I need to register these components with TService and TComponent.</p>
  
  <p>Ideally, I'd like a registration to look something like this:</p>
  
  <pre><code>container.Register&lt;IFoo, Foo&gt;((kernel, foo) =&gt; kernel.Resolve&lt;Bar&gt;(new { foo }));
  </code></pre>
  
  <p>Note that IFoo and Bar are registered with the transient life style, which means that the already-resolved instance has to be passed to Bar - it can't be "re-resolved".</p>
  
  <p>Is this possible? Am I missing something?</p>