NHibernate ISession 使用和线程安全

发布于 2024-09-29 17:11:44 字数 313 浏览 0 评论 0原文

当我将 ISession 生命周期配置为“每个 HTTP 请求”(我正在使用的 Autofac 中的 InstancePerLifetimeScope)时,NHibernate 分析器告诉我我的 Session 正在跨线程使用,这很可能是一个错误。到底是怎么回事? 我习惯于认为我应该将工作单元的范围限定为 http 请求,但似乎会话确实是跨线程使用的。

本质上,此“每个 HTTP 请求的 ISession”与 NHibernate 探查器警报发生冲突。 我哪里错了?

更新:我的 Web.config 中有一个 ContainerDisposalModule,因此处理工作正常

When I configure my ISession lifetime to be 'per HTTP request' (InstancePerLifetimeScope in Autofac which I'm using), NHibernate profiler tells me that my Session is being used across threads, which is most likely a bug. What is going on?
I'm used to thinking that I should scope unit of work to http request but it seems that session is indeed being used across threds.

Essentially this 'ISession per HTTP request' conflicts with NHibernate profiler alerts.
Where am I wrong?

UPDATE: I do have a ContainerDisposalModule in my Web.config, so the disposing works as it should

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剩余の解释 2024-10-06 17:11:44

IIS(像大多数 Web 服务器一样)使用多个线程来处理请求,因此这可能不是您的应用程序中的错误,您可以放心地忽略这些警告。

另请参阅此问题

IIS (like most web servers) uses multiple threads to serve requests so this is probably not a bug in your application and you can safely ignore the warnings.

See also this question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文