Is this really all that I have to do to achieve session per request with Ninject?
public class WebModule : NinjectModule
{
public override void Load()
{
Bind<ISession>().ToMethod(x => MvcApplication.SessionFactory.OpenSession()).InRequestScope();
}
}
Global.asax:
public class MvcApplication : NinjectHttpApplication
{
public static ISessionFactory SessionFactory = CreateSessionFactory();
public static void RegisterRoutes(RouteCollection routes) { /* Routing Stuff */ }
protected override void OnApplicationStarted()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
protected override void OnApplicationStopped()
{
SessionFactory.Dispose();
}
protected static ISessionFactory CreateSessionFactory() { /* session factory stuff */ }
protected override IKernel CreateKernel()
{
return new StandardKernel(new WebModule());
}
}
Is there anything wrong with this? It just seems too easy.