Show Blogger Panel Hide Blogger Panel
Alex Yakunin

April 8, 2010

New ASP.NET MVC Sample

I just pushed new ASP.NET MVC sample for DO4 to Google Code - actually, that's my today's attempt to create a new ASP.NET MVC application from scratch and try to efficiently use DO4 there.

So far the sample is really simple:
  • It is based on default ASP.NET MVC application template;
  • But there is a new PersonController, views and test for it. So it's possible to view, create and remove Persons there.
The sample shows how to:
  • Handle DataObjects.Net model validation errors: you must notice I don't use ASP.NET validators at all there, so all the checks are performed by validation framework integrated into DO4. See Person.OnValidate() method - there is even a type-level check. Obviously, this doesn't mean ASP.NET MVC validation is incompatible with DO4 - you can enable it by simply adding data annotations to PersonEditModel.
  • Handle version conflicts. Try to edit the same objects in two browser windows.
  • Implement View Model <-> Business Model mapping (as far as I understand, usage of separate view model is recommended pattern for ASP.NET MVC). I used pretty simple approach here - in fact, all the mapping code is located inside PersonEditModel and its base type (EntityModel), but possibly, this is even better, since the sample is purely educational now.
  • Use transactions - both in ASP.NET MVC controllers and unit tests.
  • Rollback the transaction in case of errors. SQL Profiler will show that transactions are really rolled back in case of any errors. Btw, the same is true for tests.
That's all for now. Obviously, all this stuff is crude from the point of APIs (although I tried to make the code look nicer), but clear APIs is what I'm going to do during the next week. If you'll get any ideas related to possible improvements of this sample, please leave them in comments. 

Screenshots of this sample are shown here.

P.S. Yesterday I promised to write my ideas on ASP.NET MVC helpers - as you see, this part isn't completed yet. But I hard-coded a part of them :) Tomorrow I'll try to add an advanced grid to this sample - I want to evaluate the most important use cases first.