Will the helper utility in the reference manual suffice?  And if so,
is my "GetAllTags" method the proper way to use it?

         Public Function GetAllTags() As IList(Of String)
            Dim tags As IList(Of String) = Nothing
            Dim session As ISession =
Utility.NHibernateUtil.GetCurrentSession()

            Try
                tags = session.CreateQuery("select t.Name from Tag t
group by t.Name order by t.Name") _
                .List(Of String)()
            Finally
                Utility.NHibernateUtil.CloseSession()
            End Try

            Return tags
        End Function


     Private Const CurrentSessionKey As String =
"nhibernate.current_session"
        Private Shared sessionFactory As ISessionFactory

        Shared Sub NHibernateUtil()
            sessionFactory = New Configuration().Configure
().BuildSessionFactory()
        End Sub

        Public Shared Function GetCurrentSession() As ISession
            Dim currentContext As HttpContext
            currentContext = HttpContext.Current

            Dim currentSession As ISession = currentContext.Items
(CurrentSessionKey)

            If currentSession Is Nothing Then
                currentSession = sessionFactory.OpenSession()
                currentContext.Items(CurrentSessionKey) =
currentSession
            End If

            Return currentSession
        End Function

        Public Shared Sub CloseSession()
            Dim currentContext As HttpContext
            currentContext = HttpContext.Current

            Dim currentSession As ISession = currentContext.Items
(CurrentSessionKey)

            If currentSession Is Nothing Then
                Return
            End If

            currentSession.Close()
            currentContext.Items.Remove(CurrentSessionKey)
        End Sub

        Public Shared Sub CloseSessionFactory()
            If Not sessionFactory Is Nothing Then
                sessionFactory.Close()
            End If
        End Sub

On Nov 19, 8:49 am, "Fabio Maulo" <[EMAIL PROTECTED]> wrote:
> 2008/11/19 Roger Kratz <[EMAIL PROTECTED]>
>
>
>
> > I got the impression that you recreate your IsessionFactory over and over
> > again for each request/every call to your data layer? Creating an
> > ISessionFactory is an expansive op. Create the instance in some start up
> > code for your web app and reuse it.
>
> Roger... our friend 8bit (I don't know the name) are asking here, probably,
> because he skip
> 10.1. Configurations, Sessions and Factories
> of the reference.
> We are talking about how have better reference manual but... ;)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to