title: Inject with different scope when using DbContext with custom resource provider
body: <p>In an application I have the following components (among others):</p>
  
  <ul>
  <li><code>MyDbContext</code> : Entity framework data access</li>
  <li><code>DBResourceProviderFactory</code> : A custom <code>ResourceProviderFactory</code> providing a custom <code>IResourceProvider</code> (called <code>DBResourceProvider</code>...)</li>
  <li>Other services</li>
  <li>StructureMap</li>
  </ul>
  
  <p>The custom resource provider is looking resources up in the db using <code>MyDbContext</code>, injected similarly as described in <a href="https://stackoverflow.com/a/10633095/63733">this SO answer</a>.</p>
  
  <p>The <code>MyDbContext</code> is also used in various other services, and since it is a web application, I use StructureMaps <code>HttpContextScoped</code> method to limit the lifetime of <code>MyDbContext</code> to the lifetime of the request (see <a href="https://stackoverflow.com/q/6390608/63733">an other SO question and its answer on this subject</a>):</p>
  
  <pre><code>x.For&lt;MyDbContext&gt;().HttpContextScoped();
  </code></pre>
  
  <p>However, it seems that the lifetime of an <code>IResourceProvider</code> is not limited to a single http request. Therefore, <code>DBResourceProvider</code> keeps hanging onto a <code>MyDbContext</code> reference which will be disposed after the first request.</p>
  
  <p><strong>How can I handle this <em>lifetime mismatch</em> - have StructureMap return a transient <code>MyDbContext</code> for <code>IDbResourceProvider</code> while returning HttpContext-scoped instances to all other services?</strong></p>
  
  <p>Do I need two different implementations to do that? A marker interface?
  Or is it a bad idea to use Entity Framework to look up localized resources in the first place (performance etc.)?</p>