开发者

Use Mvc 2 with ninject 2 and NHibernate - Get SessionFactory

开发者 https://www.devze.com 2023-01-23 09:30 出处:网络
I\'m trying to combine Mvc2 with Ninject and NHibernate, and found a guide here: http://damianm.com/tech/nhibernate-mvc-and-ninject/

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 ha开发者_运维问答ve 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.


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消