Hi, many thanks for your help, however I'm unable to get it working.
I'm using ASP.Net with Castle Windsor IOC and I'm trying to set up NH
session context.
My NH facility config (configured with Binsor):

facility NHibernateFacility:
    configuration:
        factory:
            @id = 'main_fac'
            @isWeb = true
            settings(keymap):
                dialect = 'NHibernate.Dialect.MsSql2005Dialect'
                connection.provider =
'NHibernate.Connection.DriverConnectionProvider'
                connection.driver_class =
'NHibernate.Driver.SqlClientDriver'
                connection.connection_string = "${connString}"
                proxyfactory.factory_class=
'NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle'
                current_session_context_clas = "web"
            assemblies:
                assembly = 'NGTasks.DAO'

And I'm trying to 'Bind' the session context in a controller code:

public ActionResult GimmeStats()
{
        ISession ses = SessionFactory.OpenSession();
        NHibernate.Context.CurrentSessionContext.Bind(ses);
        //some component call here
        //new MyComponent().DoSomeWorkInThisSession
        NHibernate.Context.CurrentSessionContext.Unbind
(SessionFactory);
        return View();
}

But I get an error saying:

[HibernateException: No current session context configured.]
   NHibernate.Context.CurrentSessionContext.GetCurrentSessionContext
(ISessionFactory factory) +176
   NHibernate.Context.CurrentSessionContext.Bind(ISession session) +21
   ngadmin.Controllers.DashboardController.BirthDeathStats24() in C:
\dev\NGinnSuite\NGTasks\www\Controllers\DashboardController.cs:44
   lambda_method(ExecutionScope , ControllerBase , Object[] ) +39
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase
controller, Object[] parameters) +17

Is there anything more I should do to initialize the session context?

R

On Aug 4, 1:43 am, Dmitiry Nagirnyak <[email protected]> wrote:
> Ohh Man,
>
> Why do I reinvent the wheel!
> I also made my ServiceLocator pluggable to any IoCs.
>
> Anoe feature I like in MY ServiceLocator is that I have Substitute method on
> the interface that I can use like this:
> using (ServiceLocator.Substitute<IDateTimeService>(new
> StaticDateTime(currentTime)) {
>   // Test whatever needed} // Here the original IDateTimeService is restored
>
> I'll lokk into the link you gave, maybe it has something similar too.
> 2009/8/4 Fabio Maulo <[email protected]>
>
>
>
> > This is what you should usehttp://www.codeplex.com/CommonServiceLocator
>
> >  <http://www.codeplex.com/CommonServiceLocator>As you can see it has
> > adapters for various IoC
>
> > 2009/8/3 Dmitiry Nagirnyak <[email protected]>
>
> >  I use ServiceLocator in such cases:
> >>http://martinfowler.com/articles/injection.html#UsingAServiceLocator
>
> >> Yes, basically it is needed to have some statics. But it doesn't mean that
> >> ISession/ISessoinFactory should be stored static variables.
> >> What I do is:
> >> 1) ServiceLocator provides interface accessible via static property.
> >> 2) The instance of that interface (implementation) is stored via another
> >> interface called Store.
> >> 3) I have different kinds of store: ThreadStatic, Static, PerRequest.
> >> 4) I implement ServiceLocator as a facade over the WindsorContainer, so it
> >> is easy to resolve dependencies on it as well.
>
> >> Anyway, there's MS implementation available if you like:
> >>http://msdn.microsoft.com/en-us/library/cc707905.aspx
>
> >> Cheers,
> >> Dmitriy.
> >> 2009/8/4 Fabio Maulo <[email protected]>
>
> >> Dependency Injection
>
> >>> 2009/8/3 rg <[email protected]>
>
> >>>> Thanks Fabio, naturally there's next question: you can get current
> >>>> contextual session by calling ISessionFactory.GetCurrentSession(), but
> >>>> how do you get current ISessionFactory? Do I still have to implement
> >>>> some public static field with ISessionFactory, or is it also somehow
> >>>> built into NHibernate?
> >>>> Rafal
>
> >>>> On Aug 3, 3:50 pm, Fabio Maulo <[email protected]> wrote:
> >>>> >http://nhforge.org/doc/nh/en/index.html#architecture-current-session
>
> >>>> > 2009/8/3 rg <[email protected]>
>
> >>>> > > Hi, I'd like to add some logic to my data objects by implementing
> >>>> > > additional methods. However, these methods have to access current
> >>>> > > ISession to be able to load or update any data. I could pass the
> >>>> > > ISession as a parameter to each method, but this is unacceptable for
> >>>> > > some reasons. It would be better if current session was stored
> >>>> > > somewhere where it can be publicly accessed - for example in thread
> >>>> > > local storage, so it can be retrieved by all methods executed in
> >>>> > > current thread.
> >>>> > > Passing ISession to each method is unacceptable because I want to
> >>>> call
> >>>> > > these methods using Ajax-RPC and certainly don't want to deal with
> >>>> > > ISession parameter client side (NH session is managed externally by
> >>>> > > RPC controller). Of course I can go with thread local storage, but
> >>>> > > maybe you have better ideas.
> >>>> > > Best regards
> >>>> > > Rafal
>
> >>>> > --
> >>>> > Fabio Maulo
>
> >>> --
> >>> Fabio Maulo
>
> > --
> > Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
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