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();
精彩评论