ASP.NET, Ninject and MVC: loading performance issues

Problem Description: This model works fine with one user at a time. As soon as I get multiple users at once, I get serious errors related to not closing my SqlDataReader. When I disable lazy loading like:

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

That's good, but performance is slow. This is using MVC Beta 1

Any thoughts?

Below I have a snippet of my global ASAX as well as the SessionFactory initialization code.

*********** IT'S ON MY 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;
    }
}

      

***** This is my 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


source to share


1 answer


It looks like you were not disposing of your session correctly (I had the same error with Ninject and NHibernate a month ago). It should be started at the beginning of the request and should be removed at the end. Could you please provide some code snippets where you start and delete the nhibernate session?



+1


source







All Articles