Disclaimer: I know my modelling of the repository is probably all wrong, and I will refactor it before shipping my app. But what I really want to know is about Dispose(), one of my doubts involves this incorrect implementation, but I'm hoping the answers I get here will help understand that method better for other parts of my application.
So why I think my repository is wrong? I'm using nhibernate, and from my first tutorials I read, the examples given were using the "using" keyword in every repository method (add, find, findall, etc.). When I started needing lazy loading then problems arose, so in my searches I stumbled upon Ayende's article in MSDN magazine about using nhibernate for desktop apps, and that's exactly my case. Basically the relevant point is that Session should be controlled by the presenters (forms?) Instead of being the repository's responsibility. So I basically did the opposite of what he said, because for some reason (I really can't remember) I didn't want at the time to put a reference to nhibernate in both the domain project (Which contain my nhibernate repositories) and the UI project. Maybe because I didn't want to tie UI with infrastructure... Anyways, I digress.
The point is: my repositories keep the Session open until I don't need them. And when I need some domain service that needs a repository, I pass one from the form. But only because that repository contains the Session that I need to maintain during the Services request.
For instance, I have a ComboBox which I populate with "Materials" entities retrieved via a repository. When user selects one, I pass it to method GetPricesPerMaterial(Material x)
of the "EstimatesCalculator", which needs some repositories in it's constructor, passed to it by the form Which called it. So, my repositories are IDisposable, because Session is IDisposable. I call Session.Dispose() in my repositories Dispose().
Now, the question is: just because the services (like "EstimatesCalculator") hold a reference to an IDisposable, do they need to be IDisposable too? I am sure I will Dispose those referenced IDisposables in the forms, Which created and passed them to the Services, so I think I don't need to call Repository.Dispose() in the services, but do I need to, say, set those references to null or something?
If merely have an association with the unmanaged resource (such as the ADO.NET connection contained within the NHibernate session), then don't implement IDisposable. Implement IDisposable if your class owns the unmanaged resource (NHibernate session) within your class. There are other cases to implement IDisposable too. They are referenced in the Dispose Pattern link.
Regardless make sure that you dispose of the resource. It sounds like your forms is owning session. You should simply dispose of it there.
also see: IDisposable Interface