Archive for the ‘Castle’ Category

Painless Persistence with Castle ActiveRecord

June 3rd, 2008

Finally available. This is the JAOO presentation that Ayende and I gave last year.

MR and Windsor set up screencast

May 26th, 2008

Quick, dirty and unrehearsed. Just show how to set up MR without external configuration, how to get Windsor integration enabled and setting up routing. Created to test Screenflow.

Mov file

Credits: be nice

May 22nd, 2008

I was surprised to see that Moq uses Castle’s DynamicProxy, there is no indication anywhere on the site or even in the source repository or distribution, the assembly is merged. The same is true for Rhino.Mocks. You’d have to actually dig the IL or dig into the source code to see the dependency.

Yeah, I am very aware that they are not obligated to give this credit. Apache License is very permissive. But it would be so nice if they acknowledge this, like NHibernate does. And someone has said, niceness is the currency of open source.

Categories: Castle | Top Of Page | 17 Comments » |

Some clarifications regarding Castle’s presentation

May 18th, 2008

Gojko posted the slides after his presentation. I thought I should just make some clarifications:

But it is a RC! – A bad marketing decision

Hmm, well, it could be perceived as a bad marketing decision, but there are some things preventing us from getting 1.0 out, and I have blogged about them. Even worst, I’ve switched priorities and I’m working to get our first product, donjon, in a beta stage. And to make things more complicate, a team member left just when we signed a few more projects in.

My attention to castle right now is tending to zero, as people might have noticed on the mailing list, but hopefully this is going to change real soon.


I don’t encourage people to use AR with the AR base class. Use the ARMediator and use the repository pattern or a dao pattern to increase isolation and testability.

MonoRail: Layouts

Layouts can be set through attributes or using the LayoutName or LayoutNames exposed by the ControllerContext (trunk version) or on the Controller class (RC version).

MonoRail (-) : Hashmap for view properties

On MonoRail we usually use a less static typed template engine, such as NVelocity and Brail. So you have a bridge to cross between the controllers (static typed) and the view (dynamic). MR could offer alternatives for people using more static typed engines, such as AspView.

MonoRail (-) : Windsor Integration a bit too complicated

Really? The trunk version even free you from having to set “windsorIntegration=true” on the web.config, so I dont think it’s complicated at all. I’d be interesting in hearing/reading more on this, and how we can make it simpler then…

Other than that, kudos to Gojko for putting together a great presentation!

Categories: Castle | Top Of Page | 10 Comments » |

Autoregistration without Binsor

May 13th, 2008

On my Global.cs I usually have:

private static void RegisterWebComponents()

                delegate(ComponentRegistration reg)


To get Windsor integration:

First, make the Global implement the IContainerAccessor

public class Global : HttpApplication, IContainerAccessor

Then add a static field to hold the container

private static WindsorContainer container;

The App_Start/End and the IContainerAccessor implementation:

protected void Application_Start(object sender, EventArgs e)
    container = new WindsorContainer(new XmlInterpreter());
    container.AddFacility("mr", new MonoRailFacility());


protected void Application_End(object sender, EventArgs e)

public IWindsorContainer Container
    get { return container; }

To Configure MonoRail using code

Make the global implement IMonoRailConfigurationEvents and implement the method Configure:

public class Global : HttpApplication, IContainerAccessor, IMonoRailConfigurationEvents
    public void Configure(IMonoRailConfiguration configuration)
        // Configuring ViewEngine
        configuration.ViewEngineConfig.ViewPathRoot = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Views");
        configuration.ViewEngineConfig.ViewEngines.Add(new ViewEngineInfo(typeof(NVelocityViewEngine), false));

        // You can configure other things, and hopefully in the future 
        // we can expose a kind of fluent interface to guide you on this process

MonoRail with RoutingEx on IIS7

May 9th, 2008

It takes some time to figure out how IIS7 performs its handler/module matching, and to realize that the ordered list not always reflect the real order – once you set up an order click on View Unordered List and back to View Ordered List to see if it really changed to reflect what you want.

And one complain: it would be a lot easier if IIS7 and their handlers/modules could work together to identify if the handler/module was able to deal with the request or not, this is especially true for the DefaultDocumentModule. More on that later

This is how the handlers should look (in the ordered view)



First of all, I’m using Vista Ultimate, so from what I’ve read, the integrated mode doesn’t work yet, so fall back to Classic mode.

After creating the web site or virtual folder, go to Handler Mapping and

  • Delete the handler for static files Empirical reason, I can be wrong: I wasn’t able to re-order this one as it seems to inherit from a parent configuration, deleting it saves a lot of hair
  • Add a new Module Mapping, request path: *.*, Module StaticFileModule, Restrictions: File and GET verb. I call this one StaticF
  • Add a new Script Map, request path *, Executable aspnet_isapi.dll (the whole path), name: MR. On the restrictions, uncheck the Invoke handler only if request is mapped to (maybe you could mark Folder, not sure if IIS is going to check if the folder actually exists, that would be a problem)

Now order the handlers. In my case I have a default.aspx, so I make the .aspx handler the first one.

Then you, as you dont want MonoRail handling static content, you make StaticF the next one

Finally MR handler should handle the rest of the requests.

I struggled for some time to get the DefaultDocumentModule working. The problem is that it conflicts with MR handler in its restrictions. You basically want that it handle a folder request, and redirect to one of the default document (if found). What actually happens is that it will greedily take all requests. Leaving no room for MR handler. The fix for that is changing MonoRail routing to be able to handle empty folders requests and matching a PatternRoute, something that today is not possible.

Let me know if that works for you.

Castle Workshop in London

April 23rd, 2008

I was asked to help in spreading the word about it, so here it goes.

Skills matter is going to host a free workshop on agile web development with Castle. I wish I was there, I love London – on summer time!

Gojko Adzic also blogged on what makes a good application framework.

Categories: Castle | Top Of Page | No Comments » |

Incremental development with Monorail

April 23rd, 2008

Just bumped into this. Great work, Ben.

Just personal preference-wise:

- I’d prefer not to use the BaseControllerTest class
- Instead of writing the form tags, I’d use the form helper: $Form.FormTag(“%{action=’save’}”) and $Form.EndFormTag(). Then you take advantage of automatic form field validation if you want.
- For actions that change things, I’d use [AccessibleThrough(Verb.Post)]
- I’d configure Windsor through code
- The mapper/wrapper sounds like iBatis. Why not using Repositories with Castle ActiveRecord?
- Instead of DTO you could use the domain class as a prototype. I think that simplifies the code.

The cool thing is that Ben knows TDD. He creates a dummy implementation, get the test passing, corner it, triangulate it, and then is forced to get rid of the dummy implementation. That’s the essence of “test-driven”.

The series is also a good way to compare MonoRail with MS MVC. The goals are the same, they just provide different ways to get the same result, up to you to use the one you like the most.

Bashing Castle and its committers

April 10th, 2008

Today I had lunch with two friends/former co-worker, on a project I’ve blogged about earlier. Nice to hear some things I’ve implemented – and which I completely forgot about – are still being used.

Anyways, this project obviously used Castle, from a local build on my machine back in 2005. A huge effort was taken to port it to RC2 – yes, Release Candidate 2 -then it was decided to skip RC3 altogether and go with whatever comes after, which I hope would be 1.0.

I was told that porting was a nightmare. Dealing with compiler errors because some interface changed or some method was renamed is one thing, I dare to say somewhat easy to deal with to some extend. The biggest problem lied elsewhere. Helpers were changed, specifically methods being added, removed and renamed, and those completely broke views.

I argued that these changes are considered important changes, and are registered on the changes.txt that every project under the Castle umbrella has. This document is used to later compile a list of new features, breaking changes and bug fixes.

My friend replied that they looked into that very document, and no mention to these specific changes were there. These at very minimum can be used to drive an smart Find/Replace on the views and get them ported.

To err is human, certainly, build those slips have high costs. This project started being used in Brazil, then South America and now it’s going world wide. It’s ridiculously big. My complain to him is that this went so long unstated. People should complain about these and similar problems.

Do it nicely, though, or I will ask you to contact our customer service to get your money refunded.

And yes, I’m to blame as well as all commiters. We are directly tight to the reputation Castle has, be it bad or good.

.netrocks on Windsor

April 7th, 2008

…has just been recorded. I gotta tell that an hour might not be sufficient to explain properly what IoC, IoC container and Windsor are, how they fit and how to make use of them. When it ended I was sure that there is a lot to be said on these topics. :-(

Categories: Castle | Top Of Page | 4 Comments » |