colinramsay.co.uk

HotSwap for Monorail - In Action

23 Sep 2007

Ayende quickly posted something called HotSwap, which is a little snippet of code which uses a FileWatcher, Windsor, and on-the-fly code recompilation to increase your productivity. With ASP.NET, building your code changes causes an appdomain restart, and you will typically have to wait a few seconds for the appdomain to come back up before the browser will display your changes. This basically means that when working with ASP.NET, there are no quick code changes - you always have that four second wait till you see the effects.

HotSwap resolves this by building your code for you when it detects a change. Using Windsor it can swap out the old assembly containing your code and replace it with a new dynamically created assembly containing your new code - all automatically. The key advantage of this is that it's all done in-memory, and none of the DLL files in the bin directory change. This means that you won't trigger an appdomain restart and your changes can be seen almost instantly!

I was really impressed and excited by this approach so I did a very quick screencast on the topic. I was using the Castle RC3 MSI, and created a project with Windsor integration enabled. This code only works for your controllers at the moment, but a lot of the time that'll be where you need this kind of productivity boost.

Ayende - cheers for this, and I'm sorry if I pronounced your name wrong as I've only seen it written down!

UPDATE: I've uploaded the HotswapTest Project from the screencast. You'll probably need the Castle RC3 MSI installed to build it.

Feedback or questions on this post? Create an issue on GitHub.