ASP.NET,Ninject和MVC:性能负载问题

时间:2008-12-12 02:22:01

标签: asp.net-mvc nhibernate fluent-nhibernate ninject

问题描述:此模型一次只能与一个用户一起使用。一旦我一次得到多个用户,我就会收到与未关闭我的SqlDataReader有关的严重错误。当我关闭这样的延迟加载时:

persistenceModel.Conventions.OneToManyConvention =(prop => prop.SetAttribute(“lazy”,“false”));

很好,但性能很慢。这使用MVC Beta 1

有什么想法吗?

下面我有一个全局ASAX的片段以及我的SessionFactory inialization代码。

***********这是我的GLOBAL.ASAX ********

public class MvcApplication : NinjectHttpApplication
{
    public static IKernel Kernel { get; set; }

    protected override void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        //routes.IgnoreRoute("WebServices/*.asmx");

        routes.MapRoute("CreateCategoryJson", "Admin/CreateCategoryJson/{categoryName}");
        routes.MapRoute("User", "Admin/User/{username}", new { controller="Admin", action="user" });

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

    }

    protected void Session_Start(object sender, EventArgs e)
    {
        if (Session["rSkillsContext"] == null)
        {
            string logonName = this.User.Identity.Name.Replace("NUSOFTCORP\\", string.Empty);
            rSkillsContext context = new rSkillsContext(logonName);
            Session.Add("rSkillsContext", context);
        }
    }

    protected override IKernel CreateKernel()
    {
        log4net.Config.XmlConfigurator.Configure();
        Kernel = new StandardKernel(new RepositoryModule(), new AutoControllerModule(Assembly.GetExecutingAssembly()), new Log4netModule());
        return Kernel;
    }
}

*****这是我的NHibernateHelper.cs ******

    private ISessionFactory CreateSessionFactory()
    {
        var configuration = MsSqlConfiguration
                                .MsSql2005
                                .ConnectionString.FromConnectionStringWithKey("ConnectionString")
                                .ShowSql()
                                .Raw("current_session_context_class", "web")
                                .ConfigureProperties(new Configuration());

        var persistenceModel = new PersistenceModel();

        persistenceModel.Conventions.GetForeignKeyName = (prop => prop.Name + "ID");
        persistenceModel.Conventions.GetForeignKeyNameOfParent = (prop => prop.Name + "ID");
        // HACK: changed lazy loading
        persistenceModel.Conventions.OneToManyConvention = (prop => prop.SetAttribute("lazy", "false"));

        persistenceModel.addMappingsFromAssembly(Assembly.Load(Assembly.GetExecutingAssembly().FullName));
        persistenceModel.Configure(configuration);

        return configuration.BuildSessionFactory();
    }

1 个答案:

答案 0 :(得分:1)

看起来你没有正确处理你的Session(我在一个月前与Ninject和NHibernate有同样的错误)。它应该在请求开始时开始,并应在最后处理。您能否提供启动和处理nhibernate会话的代码段?