Setup

Since I’ve been using MacVim more and more in my personal development projects, I’ve grown to have a significant amount of muscle memory. Pretty frequently now I find a string of ‘jjjj’ in the middle of my C# code as I’m trying to take a look at what it’s doing. So I figured it was time to explore the possibilities of getting viemu up and going. The biggest hurdle was my concern about losing CodeRush/Refactor Pro! support. I am heavily dependent on them so they had to play nice together. Good news. This worked out of the box. After a quick install of viemu and a firing up Visual Studio, I was off and running.

Small tweaks

I did have to make a couple of small adjustments. First was my key re-mappings. In my configs , I snagged a couple of key mappings that I’ve found really helpful. I needed these same behaviors in viemu in order to take advantage of all my muscle memory. The key was creating the .viemurc file in my home directory since it picks that file up by default.

I also had an issue with colors – I prefer dark themes both in vim & Visual Studio. By default, the highlight in viemu clashes so strongly with my theme that I had to disable it. I couldn’t get it to switch up the color schemes appropriately either so I’m guessing I’ll have to dig a bit more to get that working but overall I’m pretty happy. If I find a way to get this working properly, I’ll update the post.

On April 30th, Improving Enterprises and Microsoft are hosting the Agile.NET conference at Microsoft’s Irving office. It’s a conference that will showcase agile principles and practices as well as tools in the .NET ecosystem. I’m excited to be doing a talk on git as it’s become a big point of evangelism for me personally but I’m also interested to hear some of the other tracks of great speakers.

Regardless of whether you’re new to agile concepts or already moving towards adoption, you will have an informative and good time. Space is limited so be sure to go sign up while there are still spaces available.

I mentioned in my first post that we were using interfaces to represent our models and WHY we did it. So here’s the HOW of doing it.

Binding

As I mentioned, we used the model attribute to decorate our models when they are in the method signature. This attribute was based on the AbstractParameterBinderAttribute from MvcContrib (if you’re using ASP.NET MVC and NOT using MvcContrib, you’re probably re-inventing more than a few wheels) which is just a CustomModelBinderAttribute with a little bit of happy sprinkled in. Here’s what our binding looked like:

The GetViewData and SetViewData are pretty self-explanatory but the real heavy lifting is in that extension method. Let’s take a look at it.

DictionaryAdapter

We know that we have a giant dictionary holding on to our data and tedious mapping using strings make me itchy, not to mention it breaking my refactoring tool, so how do we push the values without them? DictionaryAdapter from Castle. This little known, under utilized piece of work was shown to me by Craig Neuwirt, it’s creator, and I’m constantly amazed at it’s usefulness. Observe the following extension method for ViewData:

It’s that simple. No, really. The DictionaryAdapter will match up the properties on the interface you defined with the corresponding elements in the ViewData and push their values into an instance of the model. All of that, without you even having to buy it dinner.

There’s more??

This approach worked great for us and gave us most of what we needed, however, this code doesn’t handle rehydrating objects from ActiveRecord – yet. But that’s a post for another night…

CORRECTION: Craig informed me that he did not create it originally but re-wrote it’s initial implementation to what it is now. Sorry for the misunderstanding.

Brad Wilson tweeted asking about using interfaces for models in an ASP.NET MVC project and I was tempted to respond but figured this, rather than the 140 character limited avenue of Twitter, would be a better medium. The short answer is that we used binders and attributes to do our heavy lifting for us so that instead of our code looking like this:

Our model attribute was responsible for pulling in the values from our ViewData and then binding them using the DictionaryAdapter (probably one of the most powerful, under-documented pieces of the whole stack) from Castle.

Advantages

Doing this allowed us to keep our dealings with the models strongly typed (yes, this is NOT unique to using interfaces vs. classes), minimized the code needed for the model since it’s just an interface but also keeps anyone from “accidentally” pushing logic down into the model that belongs elsewhere.

Tomorrow night (Thursday), I’ll be speaking at the C# SIG. Since I’ve been watching so many TED videos, I’ve come to think that NO ONE should expound for 2 hours on any single subject – the quantity is just overwhelming. To that end, I’ll be breaking up my time and doing not 1 but *2* presentations.

Building a Castle: Introduction to Windsor

Getting introduced to Castle Windsor can be a daunting thing, I know since I’ve gone thru it. But under the covers, there is a great power. This talk will introduce the concepts as well as the methods to harness and take full advantage of all that power without getting overwhelmed.

CodeRush Ninja Training

If your not using a productivity tool, you’re ripping off your customers and wasting your time. We will take a look at how CodeRush can help you to be more productive in code and have a great time doing it. With a little practice, you can learn to be a CodeRush ninja too.

This Friday, Improving Enterprises and Microsoft are putting on a 1-day FREE (as in beer) conference to showcase agile methods in a .NET ecosystem. I will be giving my “Refactoring To Patterns” talk on the development track but there will also be two other tracks (Biz/PM related & Requirements/QA related) and number of knowledgeable speakers. I’m really looking forward to hanging out with folks and sharing ideas on how we can better promote and utilize the systems we work with to adopt agile practices and principles.

Regardless of whether you’re new to agile concepts or already moving towards adoption, you will have an informative and good time. If you’re interested, go sign up while there are still spaces available.

Having only thrown myself into the community relatively recently, I was honored (and a bit surprised) to have been given this award. I look forward to the opportunity to continue sharing the things that I’ve learned and spreading the motivation to become a better developer. I want to thank my family for putting up with my extracurricular activities and being supportive of me following my passions. Also, a thank you to Microsoft – I take back like 3 of those things I said about you last week.

Next on my list of awards to achieve, an honorable hair mention from Justice Gray…