开发者

Thread safety around "web" CurrentSessionContext / ISessionFactory.GetCurrentSession

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜