ASP.NET,Ninject和MVC:性能负载问题
-
21-08-2019 - |
题
问题的说明:这种模式工作正常,并以每次一个用户。当我得到多个用户同时,我得到一个严肃与不收我的SqlDataReader的错误。当我关闭延迟加载这样的:
persistenceModel.Conventions.OneToManyConvention =(丙=> prop.SetAttribute( “懒”, “假”));
这很好,但性能很慢。这将使用MVC测试版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();
}
解决方案
看起来你没有正确处置您的会话(我一个月前曾与Ninject和NHibernate同样的错误)。它应该在的请求的开始启动,并应在结束处。能否请您提供的代码段,你开始和处理您的NHibernate的会议?
不隶属于 StackOverflow