Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net “螺纹周围的安全性”;“网络”;CurrentSessionContext/ISessionFactory.GetCurrentSession_Asp.net_Nhibernate_Thread Safety - Fatal编程技术网

Asp.net “螺纹周围的安全性”;“网络”;CurrentSessionContext/ISessionFactory.GetCurrentSession

Asp.net “螺纹周围的安全性”;“网络”;CurrentSessionContext/ISessionFactory.GetCurrentSession,asp.net,nhibernate,thread-safety,Asp.net,Nhibernate,Thread Safety,我看到一些代码在以下代码周围加了锁: if (!CurrentSessionContext.HasBind(sessionFactory)) { CurrentSessionContext.Bind(sessionFactory.OpenSession()); } ISession session = sessionFactory.GetCurrentSession(); sessionFactory是注入DI的单例,配置使用“web”(而不是“托管web”)上下文 假设此代码不需

我看到一些代码在以下代码周围加了锁:

if (!CurrentSessionContext.HasBind(sessionFactory))
{
     CurrentSessionContext.Bind(sessionFactory.OpenSession());
}

ISession session = sessionFactory.GetCurrentSession();
sessionFactory
是注入DI的单例,配置使用“web”(而不是“托管web”)上下文

假设此代码不需要同步访问,对吗?

没错

由于web上下文使用HttpContext.Items,所以没有需要手动管理的共享状态