title: Autofac and Quartz.Net Integration
body: <p>Does anyone have any experience integrating <strong>autofac</strong> and <strong>Quartz.Net</strong>?  If so, where is it best to control lifetime management -- the IJobFactory, within the Execute of the IJob, or through event listeners? </p>
  
  <hr>
  
  <p>Right now, I'm using a custom autofac <code>IJobFactory</code> to create the <code>IJob</code> instances, but I don't have an easy way to plug in to a <code>ILifetimeScope</code> in the IJobFactory to ensure any expensive resources that are injected in the IJob are cleaned up.  The job factory just creates an instance of a job and returns it.  Here are my current ideas (hopefully there are better ones...)</p>
  
  <ul>
  <li><p>It looks like most AutoFac integrations somehow wrap a <code>ILifetimeScope</code> around the unit of work they create.  The obvious brute force way seems to be to pass an <code>ILifetimeScope</code> into the <code>IJob</code> and have the <code>Execute</code> method create a child <code>ILifetimeScope</code> and instantiate any dependencies there.  This seems a little too close to a service locator pattern, which in turn seems to go against the spirit of autofac, but it might be the most obvious way to ensure proper handling of a scope.</p></li>
  <li><p>I could plug into some of the Quartz events to handle the different phases of the Job execution stack, and handle lifetime management there.  That would probably be a lot more work, but possibly worth it if it gets cleaner separation of concerns.</p></li>
  <li><p>Ensure that an IJob is a simple wrapper around an <code>IServiceComponent</code> type, which would do all the work, and request it as <code>Owned&lt;T&gt;</code>, or <code>Func&lt;Owned&lt;T&gt;&gt;</code>.  I like how this seems to vibe more with autofac, but I don't like that its not strictly enforceable for all implementors of IJob.</p></li>
  </ul>