【问题标题】:NHibernate Session Management w/ Ninject带有 Ninject 的 NHibernate 会话管理
【发布时间】:2010-08-27 16:19:00
【问题描述】:

这真的是我必须做的所有事情来使用 Ninject 实现每个请求的会话吗?

public class WebModule : NinjectModule
{
    public override void Load()
    {            
        Bind<ISession>().ToMethod(x => MvcApplication.SessionFactory.OpenSession()).InRequestScope();            
    }
}

全球.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());
    }
}

这有什么问题吗?这似乎太容易了。

【问题讨论】:

    标签: c# .net asp.net nhibernate orm


    【解决方案1】:

    阅读this post 后,我决定不这样做。除非有人说出来,否则我会这样做the old fashioned way

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-15
    • 1970-01-01
    • 2012-09-01
    • 2010-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多