I am having a heck of a time trying to figure out my session management woes in NHibernate. I am assuming that a lot of my trouble is due to lack of knowledge of IoC and AOP concepts; at least that is what I am thinking by where Fabio Maulo keeps directing me.
Anyways, my problem is that I have a win forms application that is making "get" calls and binding the result to a grid. After binding the user may perform some kind of "write" action and those result in the session being closed after the write in an attempt to use the session per use concept. Then the user may scroll through the grid which causes the lazy loading to kick off and now the session has been closed and I get an exception.
I do not want to make my view cognizant of my sessions, I don't want to send off a KillAllSessions when the user closes the form. Plus a user may have multiple forms open at any given time further compounding the issues associated with that method. I essentially want all of this to work "behind the scenes".
So my idea thus far is to intercept the lazy loading call and check to see if the session is open and if not re-open it, get the information then re-close it. However, as far as I can tell, which isn't much, this is essentially how the lazy loading works anyways. It is intercepted by the proxy factory (NHibernate.Bytecode.Castle) and then retrieves the data using the session. So I need to actually intercept that call then pass it on to the original intended intercept after re-opening the session. So that is my idea.
My question is essentially first of all is this even the right way to go about this? Second if it is I don't even know where to start. I have never done any intercepting of method calls, I knew of it in theory but not in practice. I know there are libraries out there that do this kind of thing such as Rhino Commons, but I want to take this opportunity to learn and become a better programmer. I am trying to understand AOP and Context Bound Objects but currently I am not grokking it. Could some of you folks please help a guy out?