Converting from StructureMap to Castle Windsor?

Recently, I’ve had some problems with StructureMap. Mostly incomplete documentation, but also they have a habit of drastically changing namespacing, object names, removing methods, and generally changing how the thing works.

For now, my code is written using poor man’s DI so that I can keep working on it, but I don’t want to leave it that way. I took a look at Castle Windsor a while back, but never really tackled it. Now, after taking another look, I need a bit of help in doing the migration.

With StructureMap, I would derive a custom Registry class where all the mapping is done, a custom Bootstrap class which loads one or more registry classes and initializes them, and then, call Configure on the bootstrap class in Global.asax.

How does one go about setting up the matching Castle code? I also need to know how the controller factory is affected. Does Castle provide a replacement, or are we left to write our own, as with StructureMap?

Thanks in advance.

For your controller factory, I would recommend using MvcContrib. There is nothing that matches the SM Registry yet, they are looking into doing something similar. We use the IWindsorInstaller interface to bundle our wiring up:


container = new WindsorContainer();
container.Install(new DefaultComponentsInstaller());


public void Install(IWindsorContainer container, IConfigurationStore store)
// Component registration here like so:






Two more quickies if you don’t mind:

  • The absolute minimum dll’s to reference would be? (Assuming I don’t need logging and so forth.)

  • What namespaces should I be using in my class files?

Again, thanks.


A good set of tuturials

I came across the following, but just cannot get things to work.

Things that aren’t working include:

container.RegisterControllers - No such method is recognized.

MvcContrib does not seem to include the WindsorControllerFactory as suggested.


It’s an extension method

from a previous thread

Also, soon the core parts of Castle will be one assembly, not sure when it’s going to be done, but it shouldn’t be too long. If you want a build of the latest trunk, checkout: :slight_smile:

This would solve a lot of a my problems I think. Here is the error I am getting at the moment.

Could not load file or assembly ‘Castle.Windsor, Version=, Culture=neutral, PublicKeyToken=407dd0808d44fbdc’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Now, I’ve downloaded and reference each dll present in the packages for Castle / Microkernel, MvcContrib and MvcContrib.Extras.

Everything seems ok code-wise in that nothing breaks on compile, but something still isn’t right. It appears to be a versioning error which doesn’t make sense. These are the latest binaries from each project.

Hahah, I feel your pain! I’m responsible for distributing OSS binaries in our company! It’s a world of hurt!

Where did you pull those binaries down from?

PS. Are you on gTalk? If so, ping me your username in a PM

Eh, I got them from the following:

Castle Windsor / Micro Kernel

MvcContrib and Extras Binaries

And no, I only have ms live chat.

I think you downloaded the latest Castle release 2.1.1 from the first link and something was buid against and is blowing up. I suspect its MvcContrib.Castle from the Extras Binaries.

So use castle dlls from the Extra Binaries or rebuild MvcContrib.Castle against 2.1.1 …