Hire me at Go Tripod.

Castle Contrib – Screencast Five

April 23rd 2007, 12:52 pm in .NET, C#, Monorail, Screencasts.

This screencast takes a break from the theme of the past few in the series and examines two of the projects within Castle’s Contrib project – CodeGenerator and ActiveWriter.

http://colinramsay.co.uk/screencasts/5/

The Monday morning blues mean this cast is a little less fluent than the others, but I hope you find it useful. Read on for some of the code snippets used in the screencast.

Here’s the snippet you need to add to your .csproj file to enable the CodeGenerator:

<Import Project="$(MSBuildExtensionsPath)\Castle.Tools.CodeGenerator\Castle.Tools.CodeGenerator.targets" />

Here’s the code for the AbstractController base class I use in the CodeGenerator segment:

using Castle.MonoRail.Framework;
using Castle.Tools.CodeGenerator.Services;
using CodeGeneratorTest.SiteMap;

namespace CodeGeneratorTest.Controllers
{
	public class AbstractController : SmartDispatcherController
	{
		private ICodeGeneratorServices _services;

		public ICodeGeneratorServices CodeGeneratorServices
		{
			get { return _services; }
		}

		public RootAreaNode Site
		{
			get { return new RootAreaNode(_services); }
		}

		protected virtual void PerformGeneratedInitialize()
		{
			_services = new DefaultCodeGeneratorServices(
				new DefaultControllerReferenceFactory(),
				new AspDotNetRedirectService(),
				new DefaultArgumentConversionService(),
				new DefaultRuntimeInformationService());
			_services.Controller = this;
		}

		protected override void Initialize()
		{
			base.Initialize();

			PerformGeneratedInitialize();
		}
	}
}

10 Responses to “Castle Contrib – Screencast Five”

  1. [...] has made available some nice screencasts about MonoRail. The one I enjoyed the most was about the Contrib. He explained the CodeGenerator that these guys came up with and others [...]

  2. Kevin Miller says:

    I loved the screencast. I was blown away by he activewrier demo and cannot wait to see how this tool matures. ADO Entity Framework is no longer shipping with a graphical designer and low and behold one for active record is sitting here in our laps. Great job getting the work out there.

  3. [...] Castle Contrib – Screencast Five [...]

  4. crimsondr says:

    watched the screencast and was amazed! unfortunately when i try it, the codegenerator crashes when trying to redirect() to an action…

  5. colinramsay says:

    Hmm, it’s probably worth putting a message on the Castle Users list:

    http://groups.google.com/group/castle-project-users?hl=en

    Then we can see if it is a bug or a usage problem.

  6. Joe says:

    All five of these were great, Colin. Thanks.

    I do have to wonder about the people naming these projects (or possibly my own lack of curiosity). From the first time I heard about ActiveWriter, I just assumed another logging or some kind of static output utility and never bothered to do any further research.

    Again, thanks!

  7. Vitaliy says:

    Correct, please
    Import shippet, should be

    Thanks. Great job!!!

  8. andriy says:

    Great cast!
    I don’t like code generator very much – i think strings are kinda nicer looking the alot of hierarchical.dot.dots

    ActiveWriter looks great! Just curiour – does it actually generate models (with source code) or only binaries???
    How suitable is it for production use?

    Hope there’ll be more casts.
    Cheers!

  9. [...] Screencast on Using CodeGenerator and ActiveWriter: Shows the basics of both of these projects and why you might want to use them in your next Castle foray. If you’ve never used either it’s worth 20 minutes of your time. In case you are unfamiliar, CodeGenerator is an MSBuild task for generating strongly typed wrapper classes for your controllers and views. ActiveWriter is a Visual Studio file type used to create ActiveRecord models using a visual designer (similar to the class designer). [...]

  10. dougre says:

    is it just me, but Colin’s voice makes me REALLY sleepy.
    I should turn you on before going to bed…

    Great stuff btw.