Hi there,
is InstanceScope.Hybrid like PerRequest one, but with a fallback?
For reference, I have these entries:
ForRequestedType<ISessionFactory>()
.CacheBy(InstanceScope.Singleton)
.TheDefault.Is.ConstructedBy(()=>new SessionFactoryMaker
().CreateFactory());
ForRequestedType<ISession>()
.CacheBy(InstanceScope.PerRequest)
.TheDefault.Is.ConstructedBy(
ctx => ctx.GetInstance<ISessionFactory>().OpenSession());
I quite like using the feature Current Session Context that allows
getting the "correct" session. For my StructureMap setup it looks
pretty primitive, and for the tests it looks e.g. like this
public class TestNHSessionContext : ICurrentSessionContext
{
private readonly ISessionFactory factory;
private ISession session;
public TestNHSessionContext(ISessionFactory factory)
{
this.factory = factory;
}
public ISession CurrentSession()
{
return session ?? (session = factory.OpenSession());
}
}
It basically makes my session a singleton throughout several tests
(the thing with the in-memory DB that disappears when you close the
session / connection).
Using the session is then via factory.GetCurrentSession();
On Oct 7, 7:52 pm, Weston Binford <
wbinf...@gmail.com> wrote:
> Jeremy asked me to help him put together an example of bootstrapping
> NHibernate with StructureMap. I was originally going to post my take
> here on the mailing list, but found issues trying to format the code.
> So, I put together a blog post:
>
>
http://trason.net/journal/2009/10/6/bootstrapping-nhibernate-with-str...