title: Setter injection on an existing service instance in Castle Windsor
body: <p>Does Castle Windsor support applying setter injection to existing service instances? I have a case in which I have no control over the creation of certain class instances while I do need to resolve dependencies for them. This rules out constructor injection but leaves the door open for setter injection since I can intercept the new instances right after they're created.</p>
  
  <p>I know Castle Windsor supports setter injection out of the box, I just don't know whether its possible (and if so: how) to leverage it explicitly without using the <code>Resolve</code> method.</p>
  
  <p>I know as well that such thing is possible in StructureMap, using the <code>ObjectFactory.BuildUp</code> method so that raises my hope of finding an equivalent in Castle Windsor.</p>
  
  <p>In case you are wondering, I'm applying dependency injection to pages in ASP.NET WebForms, providing a custom <code>PageHandlerFactory</code>. I don't want to go down the path of trying to create the page handler myself, I should leave that to the base implementation in the <code>PageHandlerFactory</code> class.</p>
  
  <pre><code>public class CustomPageHandlerFactory : PageHandlerFactory
  {
      public override IHttpHandler GetHandler(HttpContext context, string requestType, string virtualPath, string path)
      {
          IHttpHandler handler = base.GetHandler(context, requestType, virtualPath, path);
          Page page = handler as Page;
  
          if (page == null)
          {
              return handler;
          }
  
          // Resolve dependencies using setter injection...
  
          return page;
      }
  }
  </code></pre>