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.
精彩评论