开发者

Is it possible to inject custom post processing in the fetching of objects in NHibernate?

My scenario is this开发者_开发知识库. We use NHibernate as our DAL. Each and every object fetched by it, be it a single object, a collection of objects or even child objects - whatever, we have to perform certain post processing.

Currently, this custom post processing is spread around - after each fetch. I am wondering if I could restructure it in a better way. I am thinking along these lines:

  • Add custom metadata to the mapping - is it at all possible?
  • Register post fetch hooks - I hope it is possible, do not know how to do it.
  • Each time the hook method is invoked it will observe the custom attribute in the metadata and perform the custom post processing accordingly.

I really do not know if my scheme is possible. Can anyone provide any hints on it?

Thanks.


Depending what you mean with post processing, you should look into the NHibernate events and eventlisteners. Sample on nhibernate.info, the IPostLoadEventListener interface seems suited for your case.


You could add custom data to the mapping but it may invalidate the xml schema. Why not add your custom attributes in separate files maintained by your logic? (or better yet go with the built in language attributes on class members). As for post processing check the NHibernate.Cfg.Configuration.EventListeners property. You can hook your listeners there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜