Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Bootstrapping NHibernate with StructureMap
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Weston Binford  
View profile  
 More options Oct 7 2009, 1:52 pm
From: Weston Binford <wbinf...@gmail.com>
Date: Wed, 7 Oct 2009 10:52:57 -0700 (PDT)
Local: Wed, Oct 7 2009 1:52 pm
Subject: Bootstrapping NHibernate with StructureMap
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...

I would appreciate any feedback on my example.  You can comment here
or on my blog.  However, if we keep the discussion here, then I think
more people will be able to follow it.

Thanks,
Weston


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Frank L. Quednau  
View profile  
 More options Oct 8 2009, 4:02 am
From: "Frank L. Quednau" <fqued...@googlemail.com>
Date: Thu, 8 Oct 2009 01:02:35 -0700 (PDT)
Local: Thurs, Oct 8 2009 4:02 am
Subject: Re: Bootstrapping NHibernate with StructureMap
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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Weston Binford  
View profile  
 More options Oct 8 2009, 5:07 pm
From: Weston Binford <wbinf...@gmail.com>
Date: Thu, 8 Oct 2009 14:07:35 -0700 (PDT)
Local: Thurs, Oct 8 2009 5:07 pm
Subject: Re: Bootstrapping NHibernate with StructureMap

InstanceScope.Hybrid means that StructureMap will store the object in
the HttpContext, if available, or in thread local storage as a fall
back.

BTW, I believe that PerRequest, the default, means StructureMap will
give you a new object every time you request one.  PerRequest should
not be confused with an HttpRequest.  I think that your configuration
below will new up a new ISession every time you request a session.

See here for full documentation on StructureMap scoping:

http://structuremap.sourceforge.net/Scoping.htm

-Weston

On Oct 8, 3:02 am, "Frank L. Quednau" <fqued...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ryan Heath  
View profile  
 More options Oct 9 2009, 3:10 am
From: Ryan Heath <ryan.q.he...@gmail.com>
Date: Fri, 9 Oct 2009 09:10:34 +0200
Local: Fri, Oct 9 2009 3:10 am
Subject: Re: [sm-users] Re: Bootstrapping NHibernate with StructureMap
Maybe the InstanceScope.PerRequest should be deprecated and an other
name should be introduced with the exact same meaning. Just to avoid
any confusion with http requests.
A new name could be perhaps InstanceScope.NewInstance.

What do you think?

// Ryan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Frank L. Quednau  
View profile  
 More options Oct 10 2009, 12:17 pm
From: "Frank L. Quednau" <fqued...@googlemail.com>
Date: Sat, 10 Oct 2009 09:17:58 -0700 (PDT)
Local: Sat, Oct 10 2009 12:17 pm
Subject: Re: Bootstrapping NHibernate with StructureMap
Oh!
Thank goodness it's just a config change away. To be honest, I didn't
look into the Scoping Doc, just drew the conclusion too quickly.

On Oct 8, 11:07 pm, Weston Binford <wbinf...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Weston Binford  
View profile  
 More options Oct 15 2009, 11:13 am
From: Weston Binford <wbinf...@gmail.com>
Date: Thu, 15 Oct 2009 08:13:04 -0700 (PDT)
Local: Thurs, Oct 15 2009 11:13 am
Subject: Re: Bootstrapping NHibernate with StructureMap
I have updated my Bootstrapping NHibernate with StructureMap example
to move the responsibility for committing database changes to the
HttpModule.  I got tired of having to call commit in my Action
methods.  Is this the right approach?  Am worried that my UnitOfWork/
TransactionBoundary class will get too complicated.  What do you
think?

http://trason.net/journal/2009/10/10/nhibernate-transactional-boundar...

-Weston

On Oct 10, 11:17 am, "Frank L. Quednau" <fqued...@googlemail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »