title: Named singleton instance in StructureMap (Multiple nHibernate session factories)
body: <p>I have a scenario where I have two Nhibernate SessionFactorys I need to register an use with StructureMap. Only Foo needs mySessionFactory sessions.</p>
  
  <p>Like this:</p>
  
  <pre><code>For&lt;ISessionFactory&gt;().Singleton().Use(NHibernateConfiguration.GetDefaultSessionFactory());
  For&lt;ISession&gt;().HybridHttpOrThreadLocalScoped().Use(x =&gt; x.GetInstance&lt;ISessionFactory&gt;().OpenSession());
  For&lt;ISessionFactory&gt;().Singleton().Use(AnotherNHibernateConfiguration.GetDefaultSessionFactory).Named("mySessionFactory");
  For&lt;ISession&gt;().HybridHttpOrThreadLocalScoped().Use(x =&gt; x.GetInstance&lt;ISessionFactory&gt;("mySessionFactory").OpenSession()).Named("mySession");
  
  For&lt;Foo&gt;()
     .Use&lt;Foo&gt;()
     .Ctor&lt;ISession&gt;("session").Is(x =&gt; x.TheInstanceNamed("mySession"));
  </code></pre>
  
  <p>The problem is that mySessionFactory is now used everywhere when I only wanted to to be used in Foo and everywhere else should use my unnamed instance.</p>
  
  <p>What I'm I doing wrong?  </p>