Wednesday, April 08, 2009

MVC.Net, Structure Map, and TDD

So I started to watch some webcasts on mvc.net.   One of the series really interested me because the guy was going to create an entire app from the ground up following TDD, using Linq to SQL, Structure Map for Dependency Injection, and MVC.Net for his UI.

Why did this interest me?   Well I have been using NHibernate and Spring.Net and I was curious what these other technologies could do.  I really was not interested in the TDD part but surprisingly something said in the webcasts, or maybe a comment on the blog really got me thinking about it, and I think I have seen the light.


First TDD
Like I said I never really bought into Test Driven Development.  I always thought as long as you have unit tests it did not matter when you wrote just have them.  However I noticed that as he wrote code to make tests past, that is all he did.  I started thinking about all the time I wrote code based on a gut feel for what I would need, only to have wasted code.  This method kinda stops that from happening cause if it wont help the test pass you don't need it.

Another interesting point discusses was that TDD will not guarantee code correctness.  All it does for each test given some input an expected result occurs.  Yet you can still rely on those tests to tell you if things go bad.

That brings me to my next topic.... Dependency Injection with StructureMap

StructureMap
To do really good unit testing it helps to separate your concerns.  Using a Injection tool really makes this a simple task to perform.  I have been using Spring.Net.  I really wanted to look at Unity 1.1, but after reading some blog post, I was turned on to StructureMap.  Let me say after working with it for two days, and reading about it for a few more, I really love working with it. 

I like the fact StructureMap has a fluent interface, and that all the mappings can be tested.  StructureMap provides some testing interfaces.  For example you can call a method on the container and it will validate you mapping setup and if it fails it will output why in readable human text what object it has and what it was missing from the container.  StructureMap also provides a method on the ObjectFactory called WhatDoIHave.  This method will display in readable language everything in the Factory.

Another feature I like is the fact you can pull objects from the factory even if you haven't mapped them.   The factory will still return the object to you injected with anything it can from the mappings.

MVC.Net
I have to say I am really digging MVC.Net.  I have worked with ASP.NET for a long time.  I have learned the page stages, along with enjoying the dragging and dropping of controls.  Even though there are no controls I love how mvc really separates things out.  I like how easy it is to test ui controller logic.Even though I haven't tried this yet, I like that I can change the T4 Templates or even add my own.  MVC.Net is very robust in the features.  The one thing I do have trouble with is routing.  I seem to have a million routes in my application.  Part of it is the fact that I use complex keys for things and am passing multiple values around.  However, I still find it hard to write nice generic routes.  I think a cool tool would be one that would parse a site and generate some routes for you once it was done.


Wednesday, April 01, 2009

Chris Trainning Days 3 and 4 (Guidance Package Framework)

So After finally getting a feel for the guidance package framework I really understand all the great things that can be accomplished. I started thinking of having it create my solution and projects, adding the needed reference (both MS and third party) to the projects, having the proper directory structers under projects. Creating SVN repository on our svn server. Creating the build directories and setting up our project on the build server. And that can all be done by the initial setup.

Then you can customize the package to have development time recipies. These would be recipies that automate tedious tasks. One of those tasks for me is nhibernate mapping. Imagine a recipe where it gives you a wizzard, you pick the table and the columns you want mapped and then it goes off and creates, your hbm mapping file along with I[table]DAL, and you [table]DAL. How much time would that save over a life of a project, or two projects or well you get the idea. So after reading this you have to say man but there has to be a catch. Well there is. See actually you would have to write all this functionality yourself. None of these types of things are available as a plugin. The framework does allow you to easilly plug in your own actions and recipes, but they all need to be developbed by your team.

So if you are willing to invest the time, you can create yourself one heck of an automation package that can lead your development efforts.