NHibernate Interceptor - What is it

微笑、不失礼 提交于 2019-12-06 02:21:54

问题


What is NHibernate Interceptor, and what purpose does it serve in an application?

Also, in this article, I learned that using NHibernate makes a desktop application slower at startup, so to avoid this, I need to save the configuration in a file, and later load it from the saved file. How can I do that? I didn't find any examples in that tutorial.


回答1:


An interceptor allows you to execute additional functionality when an entity is retrieved / deleted / updated / inserted in the DB ...

Interceptors article

Hibernate doc

other useful info

About making your app slower: I'd suggest that you only have a look at optimizing start-up time, when it really becomes a problem.

When you build a session-factory, NHibernate will parse all the mappings, and that is an operation that is a bit expensive. But, as long as you have a limited number of entities, the performance hit isn't that big.
I have never ever had to optimize the initialization of NHibernate, because of slow startup times.

I'd suggest that you first concentrate on the core of your application -the problem you're trying to solve- and afterwards have a look on how you could improve startup performance. (If you'll ever have to do it).




回答2:


Interceptors, like the name itself says, allows you to intercept NHibernate operations (save/update/delete/load/flush/etc).

A newer, more flexible API to achieve this is the event system.

About serializing the configuration, the code is there, it's the class Effectus.Infrastructure.BootStrapper which is called at application startup.




回答3:


An interceptor's dissection series written by me can be found in here http://blog.scooletz.com/2011/02/03/nhibernate-interceptor-magic-tricks-pt-1/

hope it helps



来源:https://stackoverflow.com/questions/2034003/nhibernate-interceptor-what-is-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!