NHibernate:拦截器和监听器之间的区别

发布于 2024-07-21 07:17:59 字数 457 浏览 8 评论 0原文

查看 NHibernate 中创建/更新列的所有可能性,我主要是(Stackoverflow 问题 Ayende Rahien)通过监听器查看解决方案。

在我公司进行编程的程序员使用拦截器来实现同样的事情。

这两种解决方案有什么区别吗? (其中之一是否已过时,其中之一是首选,优点和/或缺点是什么)

Looking at all the possibilites of creation / update columns in NHibernate I mostly (Stackoverflow question, Ayende Rahien) see solutions with Listeners.

The programmer who was programming this in my company used an Interceptor to achieve the same thing.

Is there any difference between those two solutions? (Is one of them obsolete, is one of them preferred and what are the advantages and / or disadvantages)

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

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

发布评论

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

评论(2

苏别ゝ 2024-07-28 07:18:00

拦截器是旧的方式,事件侦听器是较新的并且服务于相同的目的。 所以在新项目中,推荐使用事件监听器。 您连接到新的NHibernate 事件系统

编辑:正如 Rashack 在评论中提到的,有些操作只能使用拦截器来完成。

Interceptors are the the old way, event-listeners are newer and server the same purpose. So in a new project, event-listeners are recommended. You hook up to the new NHibernate event system.

Edit: As Rashack mentions in his comment, there are some operations that can only be done using the interceptor.

偏爱你一生 2024-07-28 07:18:00

根据文档,它指出:
“如果您必须对持久层中的特定事件做出反应,您还可以使用 Hibernate 事件架构。事件系统可以另外使用,或者作为拦截器的替代品。”

两者有一些区别:

  1. < p>监听器很容易配置,即按照 hibernate 文档“在注册期间额外定义类型,可以更轻松地在配置期间打开或关闭自定义监听器”

  2. 拦截器可以通过编程和声明性方法在会话范围内或会话工厂范围内。 另一方面,以声明方式注册的侦听器无法共享实例。 如果在多个元素中使用相同的类名,则每个引用都将产生该类的单独实例。 如果您需要在侦听器类型之间共享侦听器实例,则必须使用编程注册方法。

As per documentation, it states that :
"If you have to react to particular events in your persistence layer, you can also use the Hibernate event architecture. The event system can be used in addition, or as a replacement, for interceptors. "

There are a few differences in both :

  1. Listeners are easily configurable i.e. as per hibernate doc "Having the type additionally defined during registration makes it easier to turn custom listeners on or off during configuration"

  2. Interceptors can be session-scoped or session factory scoped through programmatic as well as declarative approach. On the other hand, Listeners registered declaratively cannot share instances. If the same class name is used in multiple elements, each reference will result in a separate instance of that class. If you need to share listener instances between listener types you must use the programmatic registration approach.

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