title: Why does everyone say dependency injection in ASP.NET webforms is hard when PageHandlerFactory and IHttpHandlerFactory exist?
body: <p>So I have a legacy webforms site and am working on making it easier to maintain.  Chucking it away and rewriting it isn't an option.</p>
  
  <p>IoC is obviously one of the first things it got, but this leaves me with the service-locator pattern and a bad taste, and the wondering of whether it could be done better.  </p>
  
  <p>Various people I've talked to online and off tell me that I could do property-injection with an HttpModule that scans a Page class for properties decorated with an Inject attribute or similar, but that sounds like a Reflection hit (cached, but still) on every request.  Not appealing.</p>
  
  <p>So I was looking at other options, and came across <a href="http://msdn.microsoft.com/en-us/library/ms227439%28v=VS.85%29.aspx" rel="noreferrer">System.Web.IHttpHandlerFactory</a>, which has apparently been in the framework since v2.  One can remove the default *.aspx handler and replace it with one that uses a custom implementation, in httpHandlers web.config section.</p>
  
  <p>So, the people I've talked to aren't dumb; I thought I'd ask here.  <strong>Are there any gotchas with replacing the webforms PageHandlerFactory with an IoC-based implementation...?</strong>  </p>
  
  <p>It looks like it has both a CreateHandler and ReleaseHandler method, so life-style related memory leaks from the container keeping a reference to created components shouldn't be a problem...</p>