Posted on August 15, 2008 @ 03:14
So this week we got to start working a brand spanking new MVC project.
So far we’re leveraging Castle Windsor, NHibernate, Fluent Nhibernate, and kind of running Linq to NHibernate.
It’s amazing how quickly you can get a project up and running in such a short amount of time.
(BTW, Fluent NHibernate rocks!)
When you’re building off the trunk of these projects, it’s almost like the contributors to all these great projects are extended members of the team.
Thank you all!
Moving on… One of the things that are cool, but also slightly annoying,
is how the MVC framework parses out items from the http payload to populate any input arguments on controller actions.
It’s great how it just works, but it’s a little annoying if it’s under test and you have to add more fields, or remove fields from a form, then you have to go update the signature of the action then go update the test…. yada yada The changes just ripple down…
So one thing we tried out this week was to create a payload parser. What this guy does is take a
DTO parse out the values for each of the properties on the DTO from the current requests payload and fill it. This makes it easy to package up the form parameters in a nicely packaged DTO and fire it off down to a service layer to do some work.
So instead of declaring an action method on a controller that looks like this, where the signature would have to change based on what fields are submitted on a form:
We can write this…
This better allows us to adhere to the OCP. If we need to include additional fields on the form, we can add them to the form as long as the control name is the same as the name of the property on the DTO that it will be bound to. The implementation of the payload parser is quite primitive for now, but at the moment it’s all that we needed.