具有域上下文的 nhibernate 拦截器

发布于 2024-08-23 20:51:14 字数 233 浏览 3 评论 0原文

是否可以(以干净的方式)在 hibernate 2.1 中创建审计拦截器并将域上下文传递给它?

我想要实现的是设置一个日期时间(可以轻松完成 - 快速谷歌后找到加载文章),但设置一个对象,例如创建该项目的用户,或更改我尚未找到任何内容的实体其中涵盖了这一点。

由于我不知道应用程序请求/启动时的对象(这是我必须注册 nhibernate 拦截器的地方),所以有人知道合适的解决方法吗?

预先感谢,马克 H

Is it possible (in a clean fashion) to create an audit interceptor in hibernate 2.1 and pass in a domain context to it?

What I would like to achieve is to set a Date Time (can be done easy peasy - found loadsa articles after a quick google), but setting an object e.g. a user who created the item, or altered an entity I have yet to find anything which covers this.

Since I will not know the object at application request/start up (which is where i have to register the nhibernate interceptor), does anyone know of a suitable workaround?

Thanks in advance, Mark H

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

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

发布评论

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

评论(1

喵星人汪星人 2024-08-30 20:51:14

您可以将用户存储在当前会话 (HttpContext.Session) 中或使用线程本地 数据。然后侦听器就可以访问它。如果您采用线程本地方法,则需要为每个请求设置 if,例如使用 HttpModule。并不完美,但这就是我在java中看到它完成的方式(不完全是相同但类似的方法)。

You can store the user in the current session (HttpContext.Session) or use thread local data. It can then be accessed by the listener. If you go for the thread local approach, you will need to set if for each request, for instance with an HttpModule. Not perfect, but that's how I've seen it done in java (not exactly the same, but a similar approach).

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