Maola
Maola

Reputation: 23

Use Mvc 2 with ninject 2 and NHibernate - Get SessionFactory

I'm trying to combine Mvc2 with Ninject and NHibernate, and found a guide here: http://damianm.com/tech/nhibernate-mvc-and-ninject/

The problem is that he use Ninject 1. So i have to convert it, and I'm almost succesfull, but i still got one problem:

Im not sure how to convert the "context.Kernel.Get" here:

protected override ISession CreateInstance(IContext context)
{
   var sessionFactory = context.Kernel.Get<ISessionFactory>();
   return sessionFactory.OpenSession();
}

If you have betters ways to integrate these three libraries, please tell me.

Upvotes: 2

Views: 1188

Answers (1)

Dave Thieben
Dave Thieben

Reputation: 5427

I'm doing essentially the same thing in my project, however I'm not using a provider for ISession. here's my binding:

        Bind<ISessionFactory>()
            .ToProvider<SessionFactoryBuilder>()
            .InSingletonScope();

        Bind<ISession>()
            .ToMethod( context => context.Kernel.Get<ISessionFactory>().OpenSession() )
            .InRequestScope();

Upvotes: 2

Related Questions