Browsing Posts in Agile

Here are the code samples from some recent presentations…

Alberta Architect Forum 2007 – Creating Flexible Software

Austin .NET User Group – The NHibernate Mafia and the Persistent Ignorant Domain Model

Edmonton Code Camp 2007 – Building Applications Using ALT.NET

Thanks to everyone for attending the sessions, asking questions, and providing feedback.

I’ve been getting a lot of questions regarding VstsUnit for ReSharper 3.0. I’ve got good news and bad news.

First the bad news… I’ve been working on it off and on, though it’s offering some significant challenges. The object model is completely different and tests are executed in a dedicated test runner that ReSharper spins up. So test exploration is working, but test running is failing mysteriously without a good way to debug. The problem… I haven’t been able to connect to the transient process with a debugger – even with Debugger.Break(); in the test runner code.

Second piece of bad news… I’m trying to wrap my head around the new test running model in ReSharper. As far as I understand the new API, you get a call per test to run rather than the complete list. I’m not sure if this is going to be workable at all with VstsUnit due to unnecessary limitations imposed by Microsoft. The entire VstsUnit testing API is marked internal with [InternalsVisibleTo(MicrosoftPublicKey)]. So the only way to run the tests is through mstest.exe.

Third piece of bad news… After much struggling, VstsUnit doesn’t work for me for a whole variety of reasons. NUnit and MbUnit are just frictionless by comparison. When I absolutely must run VstsUnit (or NUnit/MbUnit), I’m using Jamie Cansdale’s TestDriven.NET. Not as pretty as the ReSharper Unit Test Explorer, but much more functional. Highly recommended.

The good news… For those of you who wish to continue using ReSharper’s Unit Test Explorer, I’ve released the source code on Google Code for both the ReSharper 2.5 and 3.0 versions. You can find it under vstsunit-resharper. If you have time and interest to work on this project, please drop me an email. I’m accepting patches… Open-mouthed I’m also releasing the code under The BSD License, which means that if JetBrains wants to grab the code and incorporate it directly into ReSharper, they are more than welcome to it!

N.B. Due to redistribution restrictions, I cannot place the required Visual Studio and ReSharper DLLs into the Subversion repository. You will need to copy the files into lib\ReSharper and lib\VisualStudio. See the Readme.txt files in these directories for more information.

The ALT.NET Open Space Conference in Austin has come to a close. It was a fantastic experience. I had an opportunity to connect with many people whose books I have read and tools I use. Thanks to everyone who came for sharing their time and knowledge. Given that I’m used to wearing the presenter hat, it was a refreshing change to attend a conference where the purpose was to discuss and question our core tenets. Which brings me to…

What is ALT.NET? This continues to be a hotly debated topic – before, during, and after the conference. My own take… ALT.NET is about considering alternatives, it is not about being alternative. It is about taking the best frameworks and tools from Microsoft, third-parties, and the open source community to build an application that is maintainable. It is not about being anti-Microsoft. Scott Hanselman suggested that Pragmatic.NET might have been a better name. I would tend to agree. At heart, everyone there was a pragmatic developer. (If you have not read The Pragmatic Programmer: From Journeyman to Master by Andrew Hunt and David Thomas, you really should.) It’s about thinking outside the Microsoft MSDN canon when building software.

What I find truly amusing is that, as far as I can tell, Microsoft has not attempted to create a canon. The collective knowledge has been created by regular people like us and people are fallible. Ideas that seem good at first may not stand the test of time. (DataSets/DataAdapters are a great example of an idea that in hindsight isn’t such a great one.) Microsoft is very open to better ways of developing software, as evidenced by the fact that many Microsoft employees attended. What many perceive as hostility to the community is more often disconnection from the community. But the honest truth is that they want to engage with us. I had great conversations with Simon Guest (Architecture Strategy Team), Howard Dierking (Editor in Chief of MSDN Magazine), Scott Guthrie (DevDiv), Peter Provost (P&P Team) Scott Hanselman (newest member of the Borg), and many other ‘softies about the values of the ALT.NET community and how Microsoft technologies support or hinder the development of maintainable software. (My intended purpose isn’t name dropping, but to show you, dear reader, that it’s the movers-and-shakers in Microsoft who are interested in providing a better development experience. These are the people who shape the platform and its documentation.)

Some people, who didn’t attend, have claimed that the conference was cliquey; that it was a venue for like-minded developers to say, “I do TDD.” and another developer to say, “Hey, cool. I do TDD too. You’re awesome.” On the contrary, the purpose was to foster better understanding of new techniques, such as BDD, specifications, domain-specific languages, FIT, etc. The conversations all started with a mutual understanding of what we were trying to achieve – more maintainable software supported by appropriate test artifacts.

For example, there was a lot of discussion around specification languages (like NBehave) were valuable compared with a written story on an index card. A written story is approachable by a non-technical business stakeholder and can elicit a discussion that might not otherwise happen. A specification written in C# (or Ruby) sitting in a source control system is not approachable by the non-technical business stakeholder. The answer is it depends on the individuals involved in the project. Each technique causes friction and your choice depends on which type of friction results in less project risk.

Another topic that has been widely reported is Scott Guthrie’s first public demonstration of the new ASP.NET MVC Framework. There were some pleasant surprises, including:

  • Microsoft’s commitment to testability. Controllers interact with the ASP.NET pipeline through IHttpRequest/Response rather than HttpRequest/Response. That little “I” allows us to mock out the dependency on the HTTP pipeline and run controller tests without all the ASP.NET hosting infrastructure. (ScottGu is looking to port those interfaces back into ASP.NET WebForms too.)
  • Microsoft will provide easy integration with a variety of other frameworks. For instance, if you want to mock a dependency, you can use Rhino Mocks, NMock, or TypeMock. If you want to use an inversion of control (IoC) container, Microsoft will allow you to bolt in Castle Windsor, Spring.NET, StructureMap, or ObjectBuilder. The team is even planning on providing templates for these open source frameworks. Microsoft is working with the community rather than trying to compete against it.
  • ScottGu’s team is not trying to wedge MVC into the existing WebForms model. If you use MVC, you are opting out of viewstate, postbacks, and the dreaded ASP.NET Page lifecycle. This is a brave move to make. WebForms will still work as it always has, but if you choose MVC, you will use a new set of controls specifically designed for the MVC model.
  • The bi-directional routing engine looks awesome. It allows for very flexible and human-readable URLs. The use of lambdas to create URLs was very cool.
  • The default view engine is ASP.NET. So you get all the design-time, CSS, and Intellisense support, but without the complex ASP.NET Page lifecycle, as noted above. You can easily create typed view data to communicate between your controller and view. (In MonoRail, the controller and view communicate via an untyped property bag. So you don’t get Intellisense and refactoring support.)

Overall, the design of ASP.NET MVC looks a lot like Castle MonoRail and has aspects of Ruby on Rails and Django sprinkled in. I’m looking forward to watching this technology develop. Jeremy Miller echoes my sentiments when he says, “I’m more excited about an upcoming Microsoft technology than anything else since moving from VB6 to .Net.” If you know Jeremy, he’s a hard developer to impress. So that says a lot!

There was so much more. I’ll try to put my thoughts around other discussions in the coming days as I mentally digest everything that was discussed. I’ll leave you with some personal highlights:

  • I enjoyed finally meeting Jamie Cansdale (TestDriven.NET) and hearing that he and Microsoft had come to an amicable agreement over TestDriven.NET.
  • It was great to meet Jay Flowers and thank him for all his great work on CIFactory. I even convinced him to implement an option in CIFactory to flip from using the command-line, CCNet.exe, to the Windows Service, CCNetService.exe.
  • Rock climbing Saturday night with Scott Hanselman, Russell Ball, and others was a blast. I didn’t feel like “a monkey with fly paper gloves”, but it was still a lot of fun. Maybe I’ll take it up as a hobby… 
  • Talking to Martin Fowler over dinner about the challenges in parallel computing. He said, “Concurrency is a lot like a white fluffy bunny…” at which point he leapt up and down wildly yelling, “with fangs and a mean streak a mile wide!!!” (Fans of Monty Python’s The Holy Grail will understand the reference. If you don’t, go rent the movie right now.)

Since I’ll be in Austin for the ALT.NET Open Space Conference early next month, my friend, Jeffrey Palermo, asked me to give a talk at the Austin .NET User Group while I was in town. So without further ado…

How does NHibernate enable a persistence ignorant domain model? Why would you want a persistence ignorant domain model? Why does the NHibernate Mafia feel so strongly about persistence ignorant domain models? And who are the NHibernate Mafia anyway? This session will answer all these questions and more.

Date/time: Monday, October 8, 2007 starting at 5:30pm
Location: Microsoft MTC

Why do I do what I do? To make a difference in the lives of other developers. I was delighted to receive the following email recently.

Hi James,

I’m writing you because I just wanted to thank you!

It was about two months ago and I attended TechEd/Orlando. I have to say that it was the first time for me and it really was an honor to be the one and only chosen from approximately 300 software developers working in my company to go to Orlando. I was very impressed about the good quality of the sessions, especially on the architecture track, but your tiny little discussion on Tuesday evening really opened my mind. At that time I had been working as a software developer for 7 years with about 5 years experience in software design and project management and 5 years of .NET experience. I was fighting with a 400,000 LOC .NET legacy monster that’s used by public safety agencies around the world in security related areas. I have a team of 12 developers and we were trying really hard to keep this beast up and running and extend it with new features. I think you can imagine that most of the time we were using the trial and error approach to get new features in (just hack it in and prepare for long debugging sessions hunting weird bugs in parts of the application you never expected to be affected by the new feature…). The main problem was – guess what – the dependencies. There were about 50 classes (all singleton “Managers”), and every single manager was tied to at least 10 other managers – no interfaces at all – and that’s just one of several layers of the app… We knew that dependencies were our problem, but we had no clue how to solve it – there was this chicken/egg problem – I want to decouple my system, which needs a lot of refactoring. To ensure that I don’t break anything I’d need unit tests but I can’t use them because my system is so highly coupled ;-) We have tried TypeMock, but my feeling was that this went in the wrong direction. Needless to say that this attempt failed.

During the discussion after your session you gave me some quite useful hints:

1. Read Applying Domain Driven Design and Patterns by Jimmy Nilsson
2. Read Working Effectively with Legacy Code by Michael Feathers
3. Use ReSharper (especially for Refactoring)
4. Use a Mock-Framework (preferably RhinoMocks)
5. Use a Dependency Injection Framework like Spring.NET

I bought Jimmy Nilsson’s book in the conference store and read it cover to cover on my flight back to Vienna. Then I bought the second book and read it within one week. I started to use ReSharper more extensively to apply some of the patterns from Michael Feathers’ book to get some unit tests in place. I extracted a lot of interfaces, brought Spring.NET into action and used RhinoMocks and the VS2005 built in UnitTest-Framework to write some useful unit tests. I also used the built in code coverage functionality in combination with the unit tests. In addition we already started Design for a messaging based service application that we want to develop in a very TDDish style.

As you can see there’s a lot going on since I attended your session. It was really this discussion about agile principles that gave me sort of a boost.

So again – thanks for opening my mind and keep on doing this great work!


All I can say is wow! Karl, you did the really hard work of tackling and taming a 400 KLOC legacy monster. Kudos to you and your team.

I would like to comment on a few points…

TypeMock vs. RhinoMocks

Karl’s team tried using TypeMock to, presumably, introduce unit tests into their code. Unfortunately TypeMock too easily takes you down the wrong path. TypeMock uses the Profiling API and allows you to mock anything in the .NET Framework. Want to mock out System.String? Go right ahead. Unfortunately mocking out framework types does not get you any closer to your real goal, which is to lower the coupling and break dependencies in your system. There has been much discussion of whether TypeMock is too powerful. I wouldn’t say that it’s too powerful, but more that it encourages you to do things that aren’t necessarily a good idea – like mocking types in the .NET Framework.

RhinoMocks uses Dynamic Proxy 2 to perform its magic. In order to generate a proxy, you must mock out interfaces or abstract classes (with virtual methods). This forces you to confront your coupling and dependencies head-on. You could do the same thing with TypeMock, but it takes discipline. RhinoMocks forces you to improve your design in order to make it testable.

If you’re wondering how to retrofit unit tests into an existing code base safely, I would highly recommend checking out Michael Feather’s Working Effectively with Legacy Code mentioned above. Oren Eini (aka Ayende Rahien), the creator of RhinoMocks, wrote RhinoMocks after being inspired by this book.

Singletons and the Single Dev

As Karl mentioned, they originally had a lot of singleton managers. The code probably looked something like this:


The singleton is the most-overused Gang of Four (GoF) pattern in existence, probably because it is so easy to implement. It also leads you down the dangerous path of essentially global variables, which OOP tried to get rid of. Rather than a global string variable, we now have a static instance to which everyone couples – the “Instance”. (Hey, don’t feel bad. I once overused singletons too! Live and learn.)

Why is this bad? Because any class that uses the CustomerManager is now tightly coupled to CustomerManager. And as Karl found out, when you’ve got 50 managers, they quickly become coupled to every other manager. If you try to test any small part of your system, you end up pulling in a large fraction of the 50 managers and likely they bring along most of the rest of the system. You end up with a tangled morass of virtually untestable code. Your codebase ends up being relatively fragile because a change in one manager often ripples to every other part of the system. So making small localized changes is difficult.

The solution is to move toward interfaces and dependency injection. I’ll be writing more about this in the future, but for now, go back and read this for a refresher. Once you have dependency injection in place with unit tests and mocks, you can introduce an Inversion of Control (IoC) framework and take things to the next level. Which brings us to…

Inversion of Control (IoC) Containers

Karl and his team chose to use Spring.NET, which is a good IoC framework. There are many options for Inversion of Control containers, including Spring.NET, Castle Windsor, and StructureMap. I have personally been working with Castle Windsor and am pleased with the functionality and integration that it offers. I would encourage readers to investigate all three and make a decision for themselves. I’ve got some blogposts and screencasts coming in the next few months on the importance of IoC and how to get started with it.

VstsUnit vs. NUnit

Karl mentions using VstsUnit (aka mstest.exe) for unit testing. Even though I wrote the VstsUnit Plugin for ReSharper, I would personally recommend using NUnit or MbUnit as both are more TDD-friendly than VstsUnit. Many improvements are being made to VstsUnit in the VS 2008 release, which will make it more TDD-friendly, but for now, stick with NUnit or MbUnit.

Code Coverage

For code coverage, I would recommend using NCover and Grant Drake’s NCoverExplorer combined with NUnit or MbUnit. NCoverExplorer provides nice UI navigation of NCover results. If you want easy integration between all these tools, I would recommend checking out Jamie Cansdale’s excellent TestDriven.NET add-in for Visual Studio.


What can I say? I love JetBrain’s ReSharper. If you haven’t seen it before, it’s an add-in for Visual Studio geared toward refactoring and TDD. Doing TDD without ReSharper installed is like coding Windows Forms in Notepad. It can be done, but it’s painful. To give you another analogy… Vanilla Visual Studio is good for production line assembly of code. ReSharper turns you into an artist sculpting code to be aesthetically beautiful. JetBrain’s tagline is “Develop with pleasure!” and ReSharper definitely lives up to that. If you haven’t checked it out, I would definitely recommend downloading it and checking it out.


Karl, I am so glad that my session inspired you. I am delighted that you took the initiative to tame a 400 KLOC monster into something that’s a pleasure to work with. Thanks for taking the time to write and making my day. That’s why I do what I do.

Thanks to everyone who came out for the session to listen to tales of the NHibernate Mafia and how persistence ignorance can improve your domain model. Here is a list of recommended resources:

You can download the code here. NHibernatingNorthwind is adapted from code by Oren Eini. I haven’t included the NHibernate binaries. Download and extract NHibernate 1.2 into ..\tools\NHibernate.

If you have any questions, please don’t hesitate to email me or leave a comment.

The website is now live and accepting registrations. We’re accepting 100 lucky participants to take part in this unique event. Sign up now at If you don’t know what I’m talking about, go back and read this. Hope to see you there!!!

Coming to an Edmonton library near you… One night only…

How does NHibernate enable a persistence ignorant domain model? Why would you want a persistence ignorant domain model? Why does the NHibernate Mafia feel so strongly about persistence ignorant domain models? And who are the NHibernate Mafia anyway? This session will answer all these questions and more.

Date/time: Thursday, August 23, 2007 starting at 5:30pm
Location: Stanley A. Milner library (7 Sir Winston Churchill Square)

You can sign up on the EDMUG website.

After my DNIC video interview, John just wanted to know more about agile development. So we did it again, this time podcast-style. You can check out the audio interview here.

Coming to Austin, TX… October 5-7, 2007… Brought to you by the NHibernate Mafia themselves… 3 days of ALT.NET mayhem… See behaviours twisted, tests tortured, dependencies injected, object-relations mapped, and DSLs like you’ve never seen them before…

More seriously, what exactly is ALT.NET? David Laribee coined the term to describe developers who look outside the “official gospel” for ideas of how to develop software better.

  1. You’re the type of developer who uses what works while keeping an eye out for a better way.
  2. You reach outside the mainstream to adopt the best of any community: Open Source, Agile, Java, Ruby, etc.
  3. You’re not content with the status quo. Things can always be better expressed, more elegant and simple, more mutable, higher quality, etc.
  4. You know tools are great, but they only take you so far. It’s the principles and knowledge that really matter. The best tools are those that embed the knowledge and encourage the principles (e.g. ReSharper.)

Scott Bellware has assembled an all-star organizing committee, including:

The conference will be run in an open space format, which is very agile in nature and execution. Fundamentally OpenSpace is a conference with self-organizing sessions. If you have an idea for a session, you post it on the schedule. If you see a session that interests you, you show up. If that session sparks an idea you’d like to talk about, post your new session on the schedule. Lather, rinse, repeat… This will be my first time participating in an OpenSpace conference, but I’m excited by the concept.

You can expect topics covering:

  • Software design
  • Testing strategies and continuous integration
  • Test-Driven Development (TDD)
  • Behaviour-Driven Development (BDD)
  • Domain-Driven Development (DDD)
  • Domain-specific languages (DSLs)
  • Object-relational mapping (OR/M) using NHibernate
  • Dependency injection with Castle Windsor
  • Web development with MonoRail
  • Agile team practices, such as XP and Scrum
  • Plus anything else that attendees want to discuss

The Important Stuff

Cost: FREE! (except for the cost of airfare and accommodations)
Location: St. Edwards University Professional Education Center, Austin, TX
Date: Friday, October 5th, 2007 @ 5pm to Sunday, October 8th, 2007 @ noon
Attendance: 100 (max)

If you are interested in attending the event or would like to know more, please don’t hesitate to contact me or one of the other organizers.