title: Structure map InstanceScope.Hybrid with asp.net mvc misbehaves
body: <p>I'm really stuck here.</p>
  
  <p>I have a asp.net mvc application and use StructureMap 2.5.3 (SM) to inject service and repository classes in my controllers.
  All controller are made by a SM factory.</p>
  
  <p>I also have a Linq to SQL datacontext which I wanted to cache by hybrid.</p>
  
  <pre><code>public class DBRegistry:Registry
  {
      public  DBRegistry()
      {
          ForRequestedType&lt;SharpShopDataContext&gt;()
              .CacheBy(StructureMap.Attributes.InstanceScope.Hybrid)
              .TheDefault.IsThis(new SharpShopDataContext());
      }
  }
  </code></pre>
  
  <p>The caching doesn't seem to work and I get issues with the datacontext because of it.</p>
  
  <p>Multiple browser request all return the same dbcontext?!
  In one of my repository classes I've put this code.
  Debug.WriteLine("db hashcode: " + db.GetHashCode()+ " "+ DateTime.Now.ToString());</p>
  
  <p>where db=the datacontext
  I also print the hashcodes of the repository using the db and the service using the repository, here is a print of multiple requests:</p>
  
  <p>service hashcode: 6238972 26-3-2009 18:59:34</p>
  
  <p>repository hashcode: 21756593 26-3-2009 18:59:34</p>
  
  <p>db hashcode: 7043935 26-3-2009 18:59:34</p>
  
  <p>service hashcode: 59389065 26-3-2009 18:59:34</p>
  
  <p>repository hashcode: 8331620 26-3-2009 18:59:34</p>
  
  <p>db hashcode: 7043935 26-3-2009 18:59:34</p>
  
  <p>service hashcode: 11291358 26-3-2009 18:59:38</p>
  
  <p>repository hashcode: 13848497 26-3-2009 18:59:38</p>
  
  <p>db hashcode: 7043935 26-3-2009 18:59:38</p>
  
  <p>service hashcode: 42509361 26-3-2009 18:59:38</p>
  
  <p>repository hashcode: 56101068 26-3-2009 18:59:38</p>
  
  <p>db hashcode: 7043935 26-3-2009 18:59:38</p>
  
  <p>as you can see 7043935  is the hashcode for the datacontext every time for each request, but the service and repository get a new instance and hashcode every time.</p>
  
  <p>I get weird errors because of this, for example a dataconcurrency exception because dbcontext has an original value from 4 webrequests ago, while the database was changed by another source.</p>