Question

I'm a beginner at both NHibernate and Castle Windsor but the current application I'm working on is making use of Castle Windsor's NHibernate facility Integration level 2 i.e. using the ISessionManager.

I've compared what I need to do in order to manually persist my data and using ISessionManager and I'm not really writing less code. My question is why do I even need ISessionManager? What advantages is it offering me? What are the disadvantages of using ISessionManager?

Was it helpful?

Solution

Well first of all, you don't have to manage sessions yourself. In a web-enviroment you typically want to scope your sessions pr request. The session manager ensures that the first caller to "OpenSession" starts a new session, while nested invocations gets the same session when invoking "OpenSession". You can do the same yourself by staring/closing sessions in a httpmodule or using an AOP pattern, note that doing this implies that your are working against one database, handling multiple databases yourself gets a bit more tedious. ISessionManager handles multiple databases just as tidy as it handles one.

+ Handles sessions for you Lightweight, non intrusive Simple Easy support for working against multiple databases Hosting agnostic (works just as well with nservicebushosting as it does with IIS)

- A bit more boilerplate code in your DAL/Repositories/whatever you call it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top