views:

47

answers:

2

Dear ladies and sirs.

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.

+2  A: 

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

BennyM
Thanks, I will surely look into it. What about custom metadata? Do you know if it is possible to add custom attributes and sections to the NHibernate mapping?
mark
Again, depending what you use it for. If it's only there to do a specific "post process step" as you mention, you can do the check in event listener. Check against the type or against an attribute you've used to decorate the type with.
BennyM
+3  A: 

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.

AZ