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.

Tuesday, March 24, 2009

Chris Trainning Days 1 and 2 (Guidance Package Framework)

So one of the tasks of software development I hate is setting up new projects.  This task is tedious and repetative.  When setting up a multi-tiered application, that includes, an AOP Framework, an ORM framework, a ioc framwework, and then some type of web or forms package, not to mention build scripts and maybe a data migrations package, you could kill a whole day or more.  


Throw on top of this that a lot of times there are tasks throughout a project that you do over and over.  For example, creating a data access class, you need to create the class, an interface for the class, an NHibernate mapping hbm file, a unit test class to unit test the data access class, and probably some model class to transfer the data around.  

So there is a lot of time wasted doing trivial things when with this time we should be spending it on the real business problems we are trying to solve.  If only some of the trival tasks could be automated.

So the first thing I did was look at a few offerings.  The first one was S#arp Architecture.  Well I really did not look at it but Dan Miser did and he then held a Spider Thursdy on it.  It seemed really cool.  Thought for sure this was the answer but like all tools, it had some failures.  

The next project I looked at was Sculptured.Net.  This is an MDD tool.  What is interesting it has an idea of molds that you can use to create different applications using different frameworks. For example you could create a silverlight mold, with a Nhibernate mold, and a service library mold, then using the same model, you could import it to a project using a mvc mold, a LINQ mold and a WCF mold and they the apps would work the same.  You could also create your own molds.  Well like other tools it looks great on the basic examples but as you start making more complex models the tool starts to break down.  I do want to look into making my own molds though and see if this process is easier.

That brings me to Guidance Package Framwework from Microsoft.  I was excited about this because I have seen what it could do from using some of the Pattern and Practices Team factories.  I just did not know how poorly the documentation was wrritten.  also the waas a lack of blog posts or other articles on how to use the framework.

Well after messing with it for a day I really did not get anything to work.  Yes I could get it to register my packages and when I used my package to create my solution it tried to but errored out. I was really frustrated, so I sat down and re-looked at the help that comes with the framework.  Then all of a sudden some things started clicking.  My day 2 with the framework was much better.

My next blog post will talk about the steps I took to create a basic guidance package.  It will contain code samples and hopefully give direction for those who are starting to look at using guidance packages.

Saturday, March 21, 2009

March Madness is here