Cedar City Group: SubSonic, the best thing since crunchy peanut butter

Sunday, December 2, 2007

SubSonic, the best thing since crunchy peanut butter

My first introduction to the MVC way of doing things was via SubSonic. The project that I was working on at the time was suffering from death by n-tier. One of the worst things that could happen while working on the project was to realize that you needed a new piece of data from the database. We were going by the book so here are the steps we had to go through:


  1. Write a stored procedure to access the tables.

  2. Write the code in the dataaccess layer to call the stored procedure (thank goodness we were using the Enterprise Library which simplified that code)

  3. Write a business layer routine to call the data access layer



Death by n-tier. I guess if the business layer added any value, I could understand it, but it didn't.

I was introduced to SubSonic. SubSonic is a data layer generator that implements the ActiveRecord pattern. In a nutshell, it automatically generates the code to present your application with strongly typed data objects and collections based on your database design. It can operate in two modes: mode one automatically updates the code datlayer code for you at compile time using their build provider. This is cool, becuase you can update your database and the changes are automatically refelected in your code the next time you compile.

I prefer mode 2 where Subsonic generates code for you and places it into a separate data layer project. You have to go through some extra steps, but this method just feels better to me. This mode is also recommended if you are going to be deploying to a shared host.

SubSonic also provides a Scaffolding control that can help you prototype your data input logic quickly.

I'm by no means an expert on this stuff. But SubSonic seems like a good tool to have in your tool box.

0 comments: