开发者

Thread safety around "web" CurrentSessionContext / ISessionFactory.GetCurrentSession

开发者 https://www.devze.com 2023-02-07 11:36 出处:网络
I\'ve seen some code that puts a lock around the following code: if (!CurrentSessionContext.HasBind(sessionFactory))

I've seen some code that puts a lock around the following code:

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

ISession session = sessionFactory.GetCurrentSession();

sessionFactory is a DI-开发者_开发技巧injected singleton and the configuration uses a "web" (not "managed_web") context.

Am I correct in assuming that this code does not require synchronised access?


That's correct.

Since web context uses HttpContext.Items there's no shared state that you need to manage manually.

0

精彩评论

暂无评论...
验证码 换一张
取 消