In Ninject when I wanted to bind NHibernate's ISession to a method I'd do :
container.Bind<ISession>().ToMethod(CreateSession).InRequestScope();
While the method is :
private ISession CreateSession(IContext context)
{
var sessionFactory = context.Kernel.Get<ISessionFactory>();
if (!CurrentSessionContext.HasBind(sessionFactory))
{
var session = sessionFactory.OpenSession();
CurrentSessionContext.Bind(session);
}
return sessionFactory.GetCurrentSession();
}
How can I do the same with LightInject?