Phase 1 Complete of domain rewrite.

Today's chore after work was to start the aforementioned conversion from my old approach with just one set of objects to the new approach where I have a separate set of objects for the server and client side. Happy to say the first step is now complete (or two steps depending on how you want to look at it).

This first step was to take my objects that nHibernate will map my data into and create a set of classes that are mirror images. It is these mirrored classes that the UI will send to and receive from the service layer. My service methods will now be tasked with doing at least 1 extra step in every operation to convert the responses from the model object to the response objects. These objects are completely detached from nHibernate so there is no lazy loading to deal with here, at least not in the true sense.

The second step was to create some quick and dirty conversion methods that know how to convert from the model object to the DTO and back. Here is a quick sample from one of my simpler classes:
Where there is a collection I use a LINQ query to select and convert each element in the source collection in one quick shot. I find this whole approach a bit of a nuisance, but I've minimized it as much as possible by ensuring that every conversion is the exact same call so there is nothing to remember and very little to type.

The next step is re-writing the service layer. I will need to arrive at some means of deciding on which collections to populate when an object is sent back over the service layer and also a means of simulating lazy loading in some fashion as I assume I will need it at some point. I can always live without it.

Comments

Popular Posts