views:

51

answers:

2

I am looking for a book or blog entry on the following DDD concepts, something specific to MVC and C# code. Quick summary: partially populated domain models from special repository methods and sending only changed domain model properties as JSON back from the client.

More details:

  • If you have a Customer object but need a drop down list having only customer number and customer name, you would create a special Repository method to return a full IList of Customer but only populate the customer ID and the Customer name, leaving other properties null or empty. This saves creating tons of special classes for a view model.

  • If you are editing a Customer, you would cache the Customer object in a session variable at the server then JSON serialize the View Model containing the Customer DDL and the first customer object for the client, possibly embedding the JSON in the first Html coming from the server. It would be really nice to have the JSON resolve to the MVC controller method "object parameters" (reassembly of the post data to an object parameter from JSON).

  • The client (JavaScript) instantiates the customer object and binds the object properties to the corresponding HTML input statements of the same name. When one changes, the other changes. Also throw in a template concept for IList objects. It also flags the customer object property as dirty when the input value changes (event).

  • Upon submit, only the changed (dirty) object properties are serialized to JSON and sent back to the server. Unchanged properties are simply left out. The server will combine the cached customer object with the partial JSON customer object (changes only), submitting the resulting Customer object to the repository to persist.

It's a really great concept. I would like to read about the theory and get a to-do list.

+1  A: 

(I am not providing a book recommendation. I'm only posting an answer because I ran out of space in the comment box).

I don't think this "pattern" has much to do with DDD, but it all sounds so appealing, doesn't it?

I have to say, though, that this screams "I'm going to work so long and hard on this awesome framework that will in the end net little to no performance benefit, but I'll wedge it into my application because I spent so long on it." Either that, or trying to implement this will prevent the application from actually being realized.

ASP.NET MVC model binding does a lot of what you're aiming for, albeit not in precisely the way you describe. What it doesn't do is the "only send back dirty properties" bit, but to be honest any web application that is going to net a benefit from this after all the client-side logic is more than likely poorly designed on another level (data not paged; individual views too heavy).

I don't see any benefit from caching the object in session and this is anathema to the ASP.NET MVC system anyway.

Loading only needed objects/collections from a repository is a solved problem using a first-class object-relational mapping technology, such as NHibernate.

Save the JSON for asynchronous operations.

All of this aside, what you are describing could be loosely considered as a set of optimizations that could be implemented in a piecemeal fashion, once the core of the application is working. This ensures that you deliver some value, and only do the substantial work of implementing these optimizations (if they even prove to be such) if performance is not acceptable.

Jay
Two comments: Wouldn't it be worthwhile to make your controller responses agnostic to the views consuming them, e.g. JSON responses?
Dr. Zim
Our first prototype included MVC 2 UI templates, which worked very well to display the first form, but submitting things back was a nightmare. An order had one or more products, which had one or more prices (store editor form). We used the EditorFor( Order[i], "TemplateName", "PrefixName") which worked to bind all this data back upon submit to a single object, but it took a while. We were thinking removing HTML markup from server responses would improve this response time. Unfortunately, our customer wants to see all products in an order, so we cannot do paging.
Dr. Zim
I got the idea for storing ModelState in the TempData from the RESTful MVC 2 "PUT" and "DELETE" concepts. Also, we have about 400 to 900 products to display in a single form, where the customer doesn't want to page through items. We sorta lazy load products by loading the first 10, then append the next page of 10 everytime they reach the bottom of their scroll div.
Dr. Zim
This is actually pretty easy to do with MVC Futures and JQuery. You can also create an anonymous object within the Repository, then populate a new Domain Model object before leaving. This will only populate the fields you need, while not having POCO soup.
Dr. Zim
A: 

Phil Haack has much of this in his blog, talking about MVC 2 Futures, JSON validators, Json2.js, and the like. It all works very well. This is the post.

Dr. Zim