It all depends on how you want to build you distributed architecture. Are you planning on using remoting, Component Services (COM+) or Web services. Later, are you planning on using DTO or you're OK with using POCO objects in your view.
My experience so far is that remoting is probably the worst issue in the .NET framework. MS send mixed signals about it's remoting technology and there are no clear guidelines on what to use. (if only Spring.NET were a little more developed)
Anyways, by your comment I can assume you want to using .NET Remoting. In this case you're going to need a Service layer to use as entry point to your business componente. In this scenario you'll want to start nhibernate session (plus transaction) and commit and close it when the method end.
In order to have NH session available down your execution path, you'll have to use a sort of PersistenceManager that will make the ISession available to your DAO implementation at one point or another. In ASP.NET you you normaly use the HTTPContext.Items to put the session and make it available in any part of your code. In Remoting (and other scenarios also) you can actually do this in a more "elegant" way by using Threading.Thread.CurrentContext.SetProperty method to put the session. (if you use Reflector on HTTPContext.Items you'll se this is exactly what ASP.NET does). At a later point you can retrieve the session using the Threading.Thread.CurrentContext.GetProperty (you'll probably have to learn about this in depth on your own on how to do it right for your case).
Regarding how should you transport your domain objects to the other end of the wire depends more on your architecture implementation. You can use your normal object (rememeber you can deatach them from the session), use DTO object or even passing entire parameters (ids, dates, etc)
I hope this gets you at least started and pointing in the right direction. Remoting is hard to do right in .NET, either with nhibernate or without it.
Good luck and keep us posted on your successes (and failures)
- Roni Burd
|